Author Topic: Maintenance Archive Section for mibew-1.6.5 ONLY  (Read 16767 times)

0 Members and 1 Guest are viewing this topic.

ChrisS

  • Sr. Member
  • ****
  • Posts: 36
Maintenance Archive Section for mibew-1.6.5 ONLY
« on: July 26, 2013, 03:04:58 PM »
Hi All,
The below will add a Maintenance menu to the settings section of mibew messenger version 1.6.5 where at the moment will allow messages to be archived by number specified in the box Default: 30 day's.



Make sure you backup your files & database before implementing always use a proper file editor like  Notepad++  for doing file edits.

Do the following edits & upload the uncompressed attached rar files to the relevant directories or make the files if the rar goes missing or gets corrupt.

The following directories/files can be found inside the main messenger directory as Default called webim, However, you may of changed its name.

Open: libs/common.php

Find:
Code: [Select]
?>
Add Above:
Code: [Select]
// This function will archive ALL messages greater than ? days
function archive()
{
// date function minus ? days tells us what we need to select and move it over
$link = connect();

$sqlresult = mysql_query("UPDATE chatmessage CROSS JOIN chatconfig SET chatmessage.archive = '1' WHERE chatconfig.vckey = 'archive_date' AND chatmessage.dtmcreated < CURRENT_DATE - INTERVAL CAST(chatconfig.vcvalue AS UNSIGNED) DAY",$link) or die(' Query failed: '.mysql_error().": ".$query);

// This adds all information from chatmessage to archivechatmessage
$sqlArchive = mysql_query("INSERT INTO archivechatmessage SELECT * FROM chatmessage WHERE archive = '1'",$link) or die(' Query failed: '.mysql_error().": ".$query);

// This deletes from chatmessage
$sqlDelete = mysql_query("DELETE FROM chatmessage WHERE archive = '1'",$link) or die(' Query failed: '.mysql_error().": ".$query);

}
// end of archive function

Open: libs/settings.php
Find:
Code: [Select]
array('title' => getlocal("page_settings.tab.themes"), 'link' => "$webimroot/operator/themes.php"),Add Below:
Code: [Select]
array('title' => getlocal("page_settings.tab.maintenance"), 'link' => "$webimroot/operator/maintenance.php"),
Open: view/inc_tabber.php
Find:
Code: [Select]
function print_tabbar($maxwidth = 4)Change 4 to 5

Open: locales/en/properties

At the very bottom add the following lines or add them into the list alphabetically.
Code: [Select]
page_settings.tab.maintenance=Maintenance
settings.maintenance.intro=Welcome to the maintenance page.
settings.maintenance.archivemessagespage=Set amount of day's to archive, Default: 30
settings.maintenance.archivemessagespagedo=What would you like to do?
settings.maintenance.archivemessages=Archive messages older than set above.
settings.maintenance.error=Eg 30, Numeric only
settings.maintenance.noautherror=Not an administrator.
settings.maintenance.moved=Moved to archive, if date in range.

The Default database name is webim, YOU! may of called it something else, make sure your in the correct database before running the following.
BACKUP the database Create the following table for the messages to be archived too .

Code: [Select]
CREATE TABLE IF NOT EXISTS `archivechatmessage` (
  `messageid` int(11) NOT NULL AUTO_INCREMENT,
  `threadid` int(11) NOT NULL,
  `ikind` int(11) NOT NULL,
  `agentId` int(11) NOT NULL DEFAULT '0',
  `tmessage` text NOT NULL,
  `dtmcreated` datetime DEFAULT '0000-00-00 00:00:00',
  `tname` varchar(64) DEFAULT NULL,
  `archive` int(1) NOT NULL,
  PRIMARY KEY (`messageid`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

Add the following.

Code: [Select]
INSERT INTO `chatconfig` (`id`, `vckey`, `vcvalue`) VALUES (' ', 'archive_date', '30');
Code: [Select]
ALTER TABLE chatmessage ADD column archive int (1) DEFAULT 0;
Your done try it out.
Regards

Only if uploaded rar is missing or corrupt.

Make a new file called maintenance.php & upload to the operator directory.
Code: [Select]
<?php
/*
 * Copyright 2005-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
require_once('../libs/common.php');
require_once(
'../libs/operator.php');
require_once(
'../libs/settings.php');

$operator check_login();
csrfchecktoken();
$page = array('agentId' => '');
$errors = array();
$options = array('archive_date');
loadsettings();

// If box is checked, it grabs the box and then does the maintenance
$archive = isset($_POST['archive']);

if(
$archive == '1'){
archive();
}

if (
$settings['featuresversion'] != $featuresversion) {
$settings['featuresversion'] = $featuresversion;
update_settings();
}

foreach (
$options as $opt) {
$page[$opt] = $settings[$opt];
}

if (isset(
$_POST['archivedate'])) {
$page['archive_date'] = getparam('archivedate');
if (!is_numeric($page['archive_date'])) {
$errors[] = wrong_field("settings.maintenance.error");
}
if (count($errors) == 0) {
foreach ($options as $opt) {
$settings[$opt] = $page[$opt];
}
update_settings();
header("Location: $webimroot/operator/maintenance.php?stored");
exit;
}
}

if (isset(
$_POST['sent'])) {
if (is_capable($can_administrate$operator)) {
foreach ($options as $opt) {
$settings[$opt] = verifyparam($opt"/^on$/""") == "on" "1" "0";
}
update_settings();
header("Location: $webimroot/operator/maintenance.php?stored");
exit;

} else {
$errors[] = "settings.maintenance.noautherror";
}
}


$page['formarchivedate'] = $page['archive_date'];
$page['canmodify'] = is_capable($can_administrate$operator);
$page['stored'] = isset($_GET['stored']);

prepare_menu($operator);
setup_settings_tabs(4);
start_html_output();
require(
'../view/maintenance.php');
?>

Make a new file called maintenance.php & upload to the view directory.
Code: [Select]
<?php
/*
 * Copyright 2005-2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
    
require_once("inc_menu.php");
require_once(
"inc_tabbar.php");
   
$page['title'] = getlocal("settings.title");
$page['menuid'] = "settings";
   
function 
tpl_content() { global $page$webimroot$errors;
?>

<?php echo getlocal("settings.maintenance.intro"?>
<br />
<br />
<?php 
require_once('inc_errors.php');
?>

<?php if( $page['stored'] ) { ?>
<div id="formmessage"><?php echo getlocal("settings.saved"?></div>
<?php ?>
<?php if ($archive = isset($_POST['archive'])) { ?>
<div id="formmessage"><?php echo getlocal("settings.maintenance.moved"?></div>
<?php ?>
<form name="maintenance" method="post" action="<?php echo $webimroot ?>/operator/maintenance.php">
   <?php print_csrf_token_input() ?>
   <div>
      <?php print_tabbar(); ?>
      <div class="mform">
         <div class="formtop">
            <div class="formtopi"></div>
         </div>
         <div class="forminner">
            <div class="fieldForm">
               <div class="field">
                  <div class="flabel"><?php echo getlocal('settings.maintenance.archivemessagespagedo'?></div>
                  <br clear="all"/>
                  <div class="fvalue">
                     <input type="text" name="archivedate" size="4" value="<?php echo form_value('archivedate'?>" class="formauth"/>
                  </div>
                  <div class="fdescr"> &mdash; <?php echo getlocal('settings.maintenance.archivemessagespage'?></div>
                  <br clear="all"/>
               </div>
               <div class="fbutton">
                  <input type="image" name="archivedate" value="" src='<?php echo $webimroot.getlocal("image.button.save"?>' alt='<?php echo getlocal("button.save"?>'/>
               </div>
            </div>
         </div>
         <div class="formbottom">
            <div class="formbottomi"></div>
         </div>
      </div>
   </div>
</form>
<br clear="all"/>
<form name="maintenance" method="post" action="<?php echo $webimroot ?>/operator/maintenance.php">
   <?php print_csrf_token_input() ?>
   <div>
      <div class="mform">
         <div class="formtop">
            <div class="formtopi"></div>
         </div>
         <div class="forminner">
            <div class="fieldForm">
               <div class="field">
                  <input type="checkbox" name="archive" value='1' /> &mdash; <?php echo getlocal('settings.maintenance.archivemessages'?>
               </div>
            </div>
            <div class="fbutton">
               <input type="image" name="archive" value="" src='<?php echo $webimroot.getlocal("image.button.save"?>' alt='<?php echo getlocal("button.save"?>'/>
            </div>
         </div>
         <div class="formbottom">
            <div class="formbottomi"></div>
         </div>
      </div>
   </div>
</form>
<?php 

/* content */
   
require_once('inc_main.php');
?>
« Last Edit: September 14, 2013, 07:47:37 PM by ChrisS »

ChrisS

  • Sr. Member
  • ****
  • Posts: 36
Re: Maintenance Archive Section for mibew-1.6.5 ONLY
« Reply #1 on: July 26, 2013, 03:06:30 PM »
Reserved!