Changeset 8742

Show
Ignore:
Timestamp:
01/30/10 17:47:22 (2 years ago)
Author:
mbrevda
Message:

re #1386; inital checking of majpr backup improvements.
This probobly isnt done just yet, although simple testing seems rather posotive.
Basicly, this seeks to move all the backup settings from amportal.conf in to the
gui. DB structure is something along these lines, this MAY OR MAY NOT WORK for simple
migration, so BU first!:

CREATE TABLE IF NOT EXISTS backup ( name varchar(50) default NULL, voicemail  varchar(50) 
default NULL, recordings varchar(50) default NULL, configurations  varchar(50) default 
NULL, cdr varchar(55) default NULL, fop varchar(50)  default NULL, minutes varchar(50) 
default NULL, hours varchar(50) default NULL,  days varchar(50) default NULL, months 
varchar(50) default NULL, weekdays  varchar(50) default NULL, command varchar(200) default 
NULL, method varchar(50)  default NULL, id int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY 
(ID) );
insert into backup select * from Backup;
alter table backup add ftpuser varchar(50), add ftppass varchar(50), add ftphost  
varchar(50), add ftpdir  varchar(150), add sshuser  varchar(50), add sshkey  varchar(150), 
add sshhost  varchar(50), add sshdir  varchar(150), add emailaddr  varchar(75), add 
emailmaxsize  varchar(25), add emailmaxtype varchar(5),add admin  varchar(10), add include 
blob, add exclude blob, add sudo varchar(25);
drop table Backup;

following if a partial changelog up untill
this point:

  • Add support for new db schema
  • Rename functions to make them more freepbx complient
  • Clean and disinfect code so that it doesnt look like it was the result of an accident

between nitroglycerine-powered penny-farthing bicycles, spring-loaded notebooks,
bulletproof chainmails, flying machines, steam tanks, and giant mechanical spiders

  • Sort backups alphabeticaly
  • More code cleenup
  • More readable save query
  • More readable cron string + bug fixes
  • rename gui element names
  • Handel missing backup names gracefully
  • parts of the gui to enter additional settings
  • update backup script to reflect new db/variable structure
  • naming changes
  • dont insert blank values in to the db, so that the db sets them to null
  • Make 'now' backups use the db as its source of info
  • fix admin setting not being saved
  • fix email max type typo's

TODO:

  • proper migration, taking in to account that sqlite cant alter table
  • add all current amportal var settings in to migrated (pre-exisitngs) backups
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.7/backup/functions.inc.php

    r8594 r8742  
    2424// 
    2525 
    26 function backup_retrieve_backup_cron()
    27   global $amp_conf
    28   global $db
     26function backup_retrieve_backup_cron()
     27  global $amp_conf,$db
     28  $table_name = "backup"
    2929 
    30   $table_name = "Backup"; 
    31  
    32   $sql = "SELECT Command, ID from $table_name WHERE Method NOT LIKE 'now%'"; 
     30  $sql = "SELECT command, id from $table_name WHERE method NOT LIKE 'now%'"; 
    3331  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    3432 
    35   if(empty($results)) 
     33  if(empty($results))
    3634    // grab any other cronjobs that are running as asterisk and NOT associated with backups 
    3735    // and issue the schedule to the cron scheduler 
    38     // 
    3936    exec("/usr/bin/crontab -l | grep -v ^#\ | grep -v ampbackup.pl",$cron_out,$ret1); 
    4037    $cron_out_string = implode("\n",$cron_out); 
     
    4441 
    4542  $backup_string = ""; 
    46   foreach ($results as $result) { 
    47     $backup_string .= $result['Command']." ".$result['ID']."\n"; 
    48   } 
     43  foreach($results as $result){$backup_string.=$result['command'].' '.$result['id']."\n";} 
    4944 
    5045  // grab any other cronjobs that are running as asterisk and NOT associated with backups, 
    5146  // combine with above and re-issue the schedule to the cron scheduler 
    52   // 
    5347  exec("/usr/bin/crontab -l | grep -v '^# DO NOT' | grep -v ^'# ('  |  grep -v ampbackup.php",$cron_out,$ret1); 
    5448  $cron_out_string = implode("\n",$cron_out); 
  • modules/branches/2.7/backup/page.backup.php

    r8453 r8742  
    3131$file=isset($_REQUEST['file'])?$_REQUEST['file']:''; 
    3232$filetype=isset($_REQUEST['filetype'])?$_REQUEST['filetype']:''; 
    33 $ID=isset($_REQUEST['backupid'])?$_REQUEST['backupid']:''; 
    34 $name=isset($_REQUEST['name'])?$_REQUEST['name']:'backup'; 
     33$id=isset($_REQUEST['backupid'])?$_REQUEST['backupid']:''; 
    3534 
    3635// Santity check passed params 
    3736if (strstr($dir, '..') || strpos($dir, '\'') || strpos($dir, '"') || strpos($dir, '\'') || strpos($dir,'\`') || 
    3837    strstr($file, '..') || strpos($file, '\'') || strpos($file, '"') || strpos($file, '\'') || strpos($file,'\`') || 
    39     strpos($ID, '.') || strpos($ID, '\'') || strpos($ID, '"') || strpos($ID, '\'') || strpos($ID,'\`') || 
     38    strpos($id, '.') || strpos($id, '\'') || strpos($id, '"') || strpos($id, '\'') || strpos($id,'\`') || 
    4039    strpos($filetype, '.') || strpos($filetype, '\'') || strpos($filetype, '"') || strpos($filetype, '\'') || strpos($filetype,'\`')) { 
    4140  print "You're trying to use an invalid character. Please don't.\n"; 
     
    4342} 
    4443 
    45  
    4644switch ($action) { 
     45  case "edited": 
     46    backup_delete_set($id); 
    4747  case "addednew": 
    48     $ALL_days=isset($_POST['all_days'])?$_POST['all_days']:''; 
    49     $ALL_months=isset($_POST['all_months'])?$_POST['all_months']:''; 
    50     $ALL_weekdays=isset($_POST['all_weekdays'])?$_POST['all_weekdays']:''; 
    51  
    52     $backup_schedule=isset($_REQUEST['backup_schedule'])?$_REQUEST['backup_schedule']:''; 
    53     $name=(empty($_REQUEST['name'])?'backup':$_REQUEST['name']); 
    54     $mins=isset($_REQUEST['mins'])?$_REQUEST['mins']:''; 
    55     $hours=isset($_REQUEST['hours'])?$_REQUEST['hours']:''; 
    56     $days=isset($_REQUEST['days'])?$_REQUEST['days']:''; 
    57     $months=isset($_REQUEST['months'])?$_REQUEST['months']:''; 
    58     $weekdays=isset($_REQUEST['weekdays'])?$_REQUEST['weekdays']:''; 
    59      
    60     $backup_options[]=$_REQUEST['bk_voicemail']; 
    61     $backup_options[]=$_REQUEST['bk_sysrecordings']; 
    62     $backup_options[]=$_REQUEST['bk_sysconfig']; 
    63     $backup_options[]=$_REQUEST['bk_cdr']; 
    64     $backup_options[]=$_REQUEST['bk_fop']; 
    65    
    66     $Backup_Parms=Get_Backup_String($name,$backup_schedule, $ALL_days, $ALL_months, $ALL_weekdays, $mins, $hours, $days, $months, $weekdays); 
    67     Save_Backup_Schedule($Backup_Parms, $backup_options); 
    68   break; 
    69   case "edited": 
    70     Delete_Backup_set($ID); 
    71     $ALL_days=$_REQUEST['all_days']; 
    72     $ALL_months=$_REQUEST['all_months']; 
    73     $ALL_weekdays=$_REQUEST['all_weekdays']; 
    74  
    75     $backup_schedule=$_REQUEST['backup_schedule']; 
    76     $mins=isset($_REQUEST['mins'])?$_REQUEST['mins']:''; 
    77     $hours=isset($_REQUEST['hours'])?$_REQUEST['hours']:''; 
    78     $days=isset($_REQUEST['days'])?$_REQUEST['days']:''; 
    79     $months=isset($_REQUEST['months'])?$_REQUEST['months']:''; 
    80     $weekdays=isset($_REQUEST['weekdays'])?$_REQUEST['weekdays']:''; 
    81      
    82     $backup_options[]=$_REQUEST['bk_voicemail']; 
    83     $backup_options[]=$_REQUEST['bk_sysrecordings']; 
    84     $backup_options[]=$_REQUEST['bk_sysconfig']; 
    85     $backup_options[]=$_REQUEST['bk_cdr']; 
    86     $backup_options[]=$_REQUEST['bk_fop']; 
    87    
    88     $Backup_Parms=Get_Backup_String($name,$backup_schedule, $ALL_days, $ALL_months, $ALL_weekdays, $mins, $hours, $days, $months, $weekdays); 
    89     Save_Backup_Schedule($Backup_Parms, $backup_options); 
     48    $parms=array('all_days','all_months','all_weekdays','backup_schedule', 'name', 
     49                'mins','hours','days','months','weekdays','voicemail', 
     50                'recordings','configurations','cdr','fop', 'ftpuser', 
     51                'ftppass','ftphost','ftpdir','sshuser','sshkey','sshhost','sshdir', 
     52                'emailaddr','emailmaxsize','emailmaxtype','admin','include','exclude','sudo'); 
     53    foreach($parms as $p){ 
     54      $backup_parms[$p]=(isset($_REQUEST[$p]))?$_REQUEST[$p]:''; 
     55      } 
     56    if($backup_parms['name']==''){$backup_parms['name']='backup'.rand(000,999);}//handel missing names gracefully 
     57    backup_save_schedule(backup_get_string($backup_parms)); 
    9058  break; 
    9159  case "delete": 
    92     Delete_Backup_set($ID); 
     60    backup_delete_set($id); 
    9361  break; 
    9462  case "deletedataset": 
     
    9967  break; 
    10068  case "restored": 
    101     $Message=Restore_Tar_Files($dir, $file, $filetype, $display); 
     69    $message=backup_restore_tar($dir, $file, $filetype, $display); 
    10270    // Regenerate all the ASTDB stuff. Note, we need a way to do speedials and other astdb stuff here. 
    10371    needreload(); 
     
    11583<?php  
    11684//get unique account rows for navigation menu 
    117 $results = Get_Backup_Sets(); 
     85$results = backup_get(); 
    11886 
    11987if (isset($results)) { 
     
    138106  <input type="hidden" name="action" value="addednew"> 
    139107        <table> 
    140   <?php Show_Backup_Options(); ?> 
     108  <?php backup_showopts(); ?> 
    141109        </table> 
    142110    <h5><?php echo _("Run Schedule")?><hr></h5> 
     
    169137  <input type="hidden" name="type" value="<?php echo $type?>"> 
    170138        <table> 
    171   <?php Show_Backup_Options($_REQUEST['backupid']); ?> 
     139  <?php backup_showopts($_REQUEST['backupid']); ?> 
    172140        </table> 
    173141    <h5><?php echo _("Run Schedule")?><hr></h5> 
     
    192160    if(!is_dir($dir)) mkdir($dir); 
    193161  } 
    194   Get_Tar_Files($dir, $display, $file); 
     162  backup_list_files($dir, $display, $file); 
    195163} 
    196164else 
    197165{ 
    198   if (isset($Message)){ 
     166  if (isset($message)){ 
    199167  ?> 
    200     <h3><?php echo $Message ?></h3> 
     168    <h3><?php echo $message ?></h3> 
    201169  <?php } 
    202170  else{ 
  • modules/branches/2.7/backup/schedule_functions.php

    r8663 r8742  
    11<?php 
    2 //This file is part of FreePBX. 
    3 // 
    4 //    FreePBX is free software: you can redistribute it and/or modify 
    5 //    it under the terms of the GNU General Public License as published by 
    6 //    the Free Software Foundation, either version 2 of the License, or 
    7 //    (at your option) any later version. 
    8 // 
    9 //    FreePBX is distributed in the hope that it will be useful, 
    10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    12 //    GNU General Public License for more details. 
    13 // 
    14 //    You should have received a copy of the GNU General Public License 
    15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>. 
    16 // 
    17 // schedule_functions.php Copyright (C) 2005 VerCom Systems, Inc. & Ron Hartmann (rhartmann@vercomsystems.com) 
    18 // Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) 
    19 // 
    20  
    21 function Get_Tar_Files($dir="", $display="", $file="") { 
    22   global $type; 
    23   global $asterisk_conf; 
    24   global $amp_conf; 
    25     if (is_dir($dir)) { 
    26       if (($file!=".") && ($file!="..") && ($file!="")){ 
    27         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to delete this File Set?")."','config.php?type=$type&display=$display&action=deletedataset&dir=$dir')\">"; 
    28         echo _("DELETE ALL THE DATA IN THIS SET"); echo "<span>"; echo _("Delete this backup set and all data associated with this backup set..");echo "</span></a><br></li>"; 
    29         echo "<br>"; 
     2/* 
     3 * This file is part of FreePBX. 
     4 * 
     5 * FreePBX is free software: you can redist 
     6 * ribute it and/or modify 
     7 * it under the terms of the GNU General Public License as published by 
     8 * the Free Software Foundation, either version 2 of the License, or 
     9 * (at your option) any later version. 
     10 * 
     11 * FreePBX is distributed in the hope that it will be useful, 
     12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 * GNU General Public License for more details. 
     15 * 
     16 * You should have received a copy of the GNU General Public License 
     17 * along with FreePBX.  If not, see <http: *www.gnu.org/licenses/>. 
     18 * 
     19 * schedule_functions.php Copyright (C) 2005 VerCom Systems, Inc. & Ron Hartmann (rhartmann@vercomsystems.com) 
     20 * Asterisk Management Portal Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca) 
     21 * FreePBX Backup Module - major renovations  Copyright (C) 2010 Moshe Brevda 
     22 */ 
     23 
     24function backup_list_files($dir='', $display='', $file='') { 
     25  global $type,$asterisk_conf,$amp_conf; 
     26  $html=''; 
     27  if(is_dir($dir)){ 
     28    if(($file!=".") && ($file!="..") && ($file!="")){ 
     29      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to delete this File Set?")."','config.php?type=$type&display=$display&action=deletedataset&dir=$dir')\">"; 
     30      $html.=_("DELETE ALL THE DATA IN THIS SET").'<span>'._("Delete this backup set and all data associated with this backup set..").'</span></a><br></li><br>'; 
     31    } 
     32    if($dh = opendir($dir)){ 
     33      while(($file = readdir($dh))!== false){ 
     34        $file_arr[]=$file; 
    3035      } 
    31       if ($dh = opendir($dir)){ 
    32         while (($file = readdir($dh)) !== false) { 
    33           $file_arr[] = $file; 
    34         } 
    35         rsort($file_arr); 
    36         $count = 25; 
    37         foreach ($file_arr as $file) { 
    38           if (($file!=".") && ($file!="..") && ($dir==$amp_conf['ASTVARLIBDIR']."/backups/")) { 
    39             echo "<li><a href=\"config.php?type=$type&display=$display&action=restore&dir=$dir/$file\">$file</a><br></li>"; 
    40             $count--; 
    41           } else if (($file!=".") && ($file!="..") ) { 
    42             echo "<li><a href=\"config.php?type=$type&display=$display&action=restore&dir=$dir/$file&file=$file\">$file</a><br></li>"; 
    43             $count--; 
    44           } 
    45         } 
    46         closedir($dh); 
    47         for ($i = $count; $i > 0; $i--) { 
    48           echo "<br />"; 
     36      rsort($file_arr); 
     37      $count=25; 
     38      foreach($file_arr as $file){ 
     39        if(($file!=".") && ($file!="..") && ($dir==$amp_conf['ASTVARLIBDIR']."/backups/")){ 
     40          $html.="<li><a href=\"config.php?type=$type&display=$display&action=restore&dir=$dir/$file\">$file</a><br></li>"; 
     41          $count--; 
     42        }elseif(($file!=".") && ($file!="..")){ 
     43          $html.="<li><a href=\"config.php?type=$type&display=$display&action=restore&dir=$dir/$file&file=$file\">$file</a><br></li>"; 
     44          $count--; 
    4945        } 
    5046      } 
    51     } else if (substr($dir, -6)=="tar.gz" ){ 
    52       echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to delete this File Set?")."','config.php?type=$type&display=$display&action=deletefileset&dir=$dir&file=$file')\">"; 
    53       echo _("Delete File Set"); echo "<span>"; echo _("Delete this backup set."); echo "</span></a><br></li>"; 
    54       echo "<br>"; 
    55       $tar_string="tar tfz \"$dir\" | cut -d'/' -f4"; 
    56       exec($tar_string,$restore_files,$error); 
    57       echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to restore this COMPLETE file set?\\nDoing so will permanently over-write all FreePBX and Asterisk files\\nYou will lose all Your Call Detail Records and any Voicemail that was recorded between the BACKUP DATE and NOW!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=ALL&file=$file')\">"; 
    58       echo _("Restore Entire Backup Set");  
    59       echo "<span>";  
    60       echo _("Restore your Complete Backup set overwriting all files.");  
    61       echo "</span></a><br></li>"; 
    62       echo "<br>"; 
    63       if (array_search('voicemail.tar.gz',$restore_files)){ 
    64         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this file set?\\nDoing so will permanently delete any new voicemail you have in your mailbox\\nsince this backup on")." $file!','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=VoiceMail&file=$file')\">"; 
    65         echo _("Restore VoiceMail Files"); 
    66         echo "<span>";  
    67         echo _("Restore your Voicemail files from this backup set.  NOTE! This will delete any voicemail currently in the voicemail boxes."); 
    68         echo "</span></a><br></li>"; 
    69         echo "<br>"; 
     47      closedir($dh); 
     48      for ($i = $count; $i > 0; $i--){ 
     49        $html.='<br />'; 
    7050      } 
    71  
    72       if (array_search('recordings.tar.gz',$restore_files)){ 
    73         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this file set?\\nNOTE! This will OVERWRITE any voicerecordings currently on the system. It will NOT delete new files not currently in the backup set")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=Recordings&file=$file')\">"; 
    74         echo _("Restore System Recordings Files");  
    75         echo "<span>";  
    76         echo _("Restore your system Voice Recordings including AutoAttendant files from this backup set.  NOTE! This will OVERWRITE any voicerecordings  currently on the system. It will NOT delete new files not currently in the backup set"); echo "</span></a><br></li>"; 
    77         echo "<br>"; 
    78       } 
    79       if (array_search('configurations.tar.gz',$restore_files)){ 
    80         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this File Set?\\nDoing so will Permanently Over-Write all FreePBX and Asterisk Files!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=Configurations&file=$file')\">"; 
    81         echo _("Restore System Configuration"); echo "<span>"; echo _("Restore your system configuration from this backup set.  NOTE! This will OVERWRITE any System changes you have made since this backup... ALL items will be reset to what they were at the time of this backup set.."); echo "</span></a><br></li>"; 
    82         echo "<br>"; 
    83       } 
    84       if (array_search('fop.tar.gz',$restore_files)){ 
    85         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore the Operator Panel Files?\\nDoing so will Permanently Over-Write all Operator Panel Files!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=FOP&file=$file')\">"; 
    86         echo _("Restore Operator Panel");  
    87         echo "<span>";  
    88         echo _("Restore the Operator Panel from this backup set.  NOTE! This will OVERWRITE any Operator Panel Changes you have made since this backup... ALL items will be reset to what they were at the time of this backup set..");  
    89         echo "</span></a><br></li>"; 
    90         echo "<br>"; 
    91       } 
    92       if (array_search('cdr.tar.gz',$restore_files)){ 
    93         echo "<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore the CALL DETAIL FILES?\\nDoing so will Permanently DELETE all CALL RECORDS!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=CDR&file=$file')\">"; 
    94         echo _("Restore Call Detail Report");  
    95         echo "<span>";  
    96         echo _("Restore the Call Detail Records from this backup set.  NOTE! This will DELETE ALL CALL RECORDS that have been saved since this backup set..");  
    97         echo "</span></a><br></li>"; 
    98         echo "<br>"; 
    99       } 
    100     } else { 
    101       echo "<h2>"; echo _("ERROR its not a BACKUP SET file");echo "</h2>"; 
    102     } 
    103   } 
    104  
    105 function Restore_Tar_Files($dir="", $file="",$filetype="", $display="") { 
    106   global $asterisk_conf; 
    107   global $amp_conf; 
     51    } 
     52  }elseif(substr($dir, -6)=="tar.gz" ){ 
     53    $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to delete this File Set?")."','config.php?type=$type&display=$display&action=deletefileset&dir=$dir&file=$file')\">"; 
     54    $html.=_("Delete File Set").'<span>'._("Delete this backup set.").'</span></a><br></li><br>'; 
     55    $tar_string="tar tfz \"$dir\" | cut -d'/' -f4"; 
     56    exec($tar_string,$restore_files,$error); 
     57    $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to restore this COMPLETE file set?\\nDoing so will permanently over-write all FreePBX and Asterisk files\\nYou will lose all Your Call Detail Records and any Voicemail that was recorded between the BACKUP DATE and NOW!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=ALL&file=$file')\">"; 
     58    $html.=_("Restore Entire Backup Set").'<span>';  
     59    $html.=_("Restore your Complete Backup set overwriting all files.").'</span></a><br></li><br>'; 
     60    if(array_search('voicemail.tar.gz',$restore_files)){ 
     61      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this file set?\\nDoing so will permanently delete any new voicemail you have in your mailbox\\nsince this backup on")." $file!','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=VoiceMail&file=$file')\">"; 
     62      $html.=_('Restore VoiceMail Files').'<span>';  
     63      $html.=_('Restore your Voicemail files from this backup set.  NOTE! This will delete any voicemail currently in the voicemail boxes.'); 
     64      $html.='</span></a><br></li><br>'; 
     65    } 
     66    if(array_search('recordings.tar.gz',$restore_files)){ 
     67      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this file set?\\nNOTE! This will OVERWRITE any voicerecordings currently on the system. It will NOT delete new files not currently in the backup set")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=Recordings&file=$file')\">"; 
     68      $html.=_('Restore System Recordings Files').'<span>';  
     69      $html.=_("Restore your system Voice Recordings including AutoAttendent files from this backup set.  NOTE! This will OVERWRITE any voicerecordings  currently on the system. It will NOT delete new files not currently in the backup set").'</span></a><br></li><br>'; 
     70    } 
     71    if(array_search('configurations.tar.gz',$restore_files)){ 
     72      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore this File Set?\\nDoing so will Permanently Over-Write all FreePBX and Asterisk Files!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=Configurations&file=$file')\">"; 
     73      $html.=_("Restore System Configuration").'<span>'._("Restore your system configuration from this backup set.  NOTE! This will OVERWRITE any System changes you have made since this backup... ALL Itemes will be reset to what they were at the time of this backup set..").'</span></a><br></li><br>'; 
     74    } 
     75    if(array_search('fop.tar.gz',$restore_files)){ 
     76      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore the Operator Panel Files?\\nDoing so will Permanently Over-Write all Operator Panel Files!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=FOP&file=$file')\">"; 
     77      $html.=_("Restore Operator Panel").'<span>';  
     78      $html.=_('Restore the Operator Panel from this backup set.  NOTE! This will OVERWRITE any Operator Panel Changes you have made since this backup... ALL Itemes will be reset to what they were at the time of this backup set..').'</span></a><br></li><br>'; 
     79    } 
     80    if(array_search('cdr.tar.gz',$restore_files)){ 
     81      $html.="<li><a class=\"info\" href=\"javascript:decision('"._("Are you sure you want to Restore the CALL DETAIL FILES?\\nDoing so will Permanently DELETE all CALL RECORDS!")."','config.php?type=$type&display=$display&action=restored&dir=$dir&filetype=CDR&file=$file')\">"; 
     82      $html.=_("Restore Call Detail Report").'<span>';  
     83      $html.=_("Restore the Call Detail Records from this backup set.  NOTE! This will DELETE ALL CALL RECORDS that have been saved since this backup set..");  
     84      $html.='</span></a><br></li><br>'; 
     85    } 
     86  }else{ 
     87    $html.='<h2>'._("ERROR its not a BACKUP SET file").'</h2>'; 
     88  } 
     89  echo $html; 
     90
     91 
     92function backup_restore_tar($dir="", $file="",$filetype="", $display="") { 
     93  global $asterisk_conf,$amp_conf; 
    10894  $error = false; 
    10995  $tar='/bin/tar'; 
    110   if($amp_conf['AMPBACKUPSUDO']==true){$sudo='/usr/bin/sudo';} 
    111   if($filetype=="ALL") { 
    112  
    113     $fileholder=substr($file, 0,-7); 
    114     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    115     $error = ($error || ($ret != 0)); 
    116  
    117     // First restore voicemial (for some reason if you do it all at once these don't get restored 
    118     // 
    119     exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); 
    120     $error = ($error || ($ret != 0)); 
    121     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | $tar -Pxvz"; 
    122     exec($tar_cmd,$out_arr,$ret); 
    123     $error = ($error || ($ret != 0)); 
    124  
    125     // Next, recordings cause same issue as above 
    126     // 
    127     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | $tar -Pxvz"; 
    128     exec($tar_cmd,$out_arr,$ret); 
    129     $error = ($error || ($ret != 0)); 
    130  
    131     // Now the rest and then we'll get on with the databases 
    132     // 
    133     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | $tar -Pxvz"; 
    134     exec($tar_cmd,$out_arr,$ret); 
    135     $error = ($error || ($ret != 0)); 
    136     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz /tmp/ampbackups.$fileholder/cdr.tar.gz  | $tar -Pxvz"; 
    137     exec($tar_cmd,$out_arr,$ret); 
    138     $error = ($error || ($ret != 0)); 
    139     $tar_cmd="$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/asteriskcdr.sql /tmp/ampbackups.$fileholder/astdb.dump"; 
    140     exec($tar_cmd,$out_arr,$ret); 
    141     $error = ($error || ($ret != 0)); 
    142  
    143     $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql 2>&1"; 
    144     exec($sql_cmd,$out_arr,$ret); 
    145     $error = ($error || ($ret != 0)); 
    146     $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; 
    147     exec($sql_cmd,$out_arr,$ret); 
    148     $error = ($error || ($ret != 0)); 
    149     exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); 
    150     $error = ($error || ($ret != 0)); 
    151      
    152     //restore additional file (aka AMPPROVROOT), using sudo if requested 
    153     $tar_cmd="$sudo $tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/phoneconfig.tar.gz |$sudo $tar -Pxvz"; 
    154     exec($tar_cmd,$out_arr,$ret); 
    155     $error = ($error || ($ret != 0)); 
    156     exec("/bin/rm -rf /tmp/ampbackups.$fileholder",$out_arr,$ret); 
    157     $error = ($error || ($ret != 0)); 
    158  
    159     if (!error) { 
    160       $Message=_("Restored All Files in Backup Set"); 
    161     } 
    162  
    163   } else if($filetype=="VoiceMail") { 
    164  
    165     $fileholder=substr($file, 0,-7); 
    166     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    167     $error = ($error || ($ret != 0)); 
    168     exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); 
    169     $error = ($error || ($ret != 0)); 
    170     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | $tar -Pxvz"; 
    171     exec($tar_cmd,$out_arr,$ret); 
    172     $error = ($error || ($ret != 0)); 
    173     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    174     $error = ($error || ($ret != 0)); 
    175  
    176     if (!error) { 
    177       $Message=_("Restored VoiceMail"); 
    178     } 
    179  
    180   } else if($filetype=="Recordings") { 
    181  
    182     $fileholder=substr($file, 0,-7); 
    183     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    184     $error = ($error || ($ret != 0)); 
    185     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | $tar -Pxvz"; 
    186     exec($tar_cmd,$out_arr,$ret); 
    187     $error = ($error || ($ret != 0)); 
    188     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    189     $error = ($error || ($ret != 0)); 
    190  
    191     if (!error) { 
    192       $Message=_("Restored System Recordings"); 
    193     } 
    194  
    195   } else if($filetype=="Configurations"){ 
    196  
    197     $fileholder=substr($file, 0,-7); 
    198     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    199     $error = ($error || ($ret != 0)); 
    200     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | $tar -Pxvz"; 
    201     exec($tar_cmd,$out_arr,$ret); 
    202     $error = ($error || ($ret != 0)); 
    203     $tar_cmd="$$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/astdb.dump"; 
    204     exec($tar_cmd,$out_arr,$ret); 
    205     $error = ($error || ($ret != 0)); 
    206     $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql"; 
    207     exec($sql_cmd,$out_arr,$ret); 
    208     $error = ($error || ($ret != 0)); 
    209     exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); 
    210     $error = ($error || ($ret != 0)); 
    211     //restore additional file (aka AMPPROVROOT), using sudo if requested 
    212     $tar_cmd="$sudo $tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/phoneconfig.tar.gz |$sudo $tar -Pxvz"; 
    213     exec($tar_cmd,$out_arr,$ret); 
    214      
    215     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    216     $error = ($error || ($ret != 0)); 
    217  
    218     if (!error) { 
    219       $Message=_("Restored System Configuration"); 
    220     } 
    221  
    222   } else if($filetype=="FOP"){ 
    223  
    224     $fileholder=substr($file, 0,-7); 
    225     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    226     $error = ($error || ($ret != 0)); 
    227     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz | $tar -Pxvz"; 
    228     exec($tar_cmd,$out_arr,$ret); 
    229     $error = ($error || ($ret != 0)); 
    230     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    231     $error = ($error || ($ret != 0)); 
    232  
    233     if (!error) { 
    234       $Message=_("Restored Operator Panel"); 
    235     } 
    236  
    237   } else if($filetype=="CDR"){ 
    238  
    239     $fileholder=substr($file, 0,-7); 
    240     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    241     $error = ($error || ($ret != 0)); 
    242     $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/cdr.tar.gz | $tar -Pxvz"; 
    243     exec($tar_cmd,$out_arr,$ret); 
    244     $error = ($error || ($ret != 0)); 
    245     $tar_cmd="$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asteriskcdr.sql"; 
    246     exec($tar_cmd,$out_arr,$ret); 
    247     $error = ($error || ($ret != 0)); 
    248     $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; 
    249     exec($sql_cmd,$out_arr,$ret); 
    250     $error = ($error || ($ret != 0)); 
    251     exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
    252     $error = ($error || ($ret != 0)); 
    253  
    254     if (!error) { 
    255       $Message=_("Restored CDR logs"); 
    256     } 
    257  
    258   } 
    259   if (! $error) { 
    260     $Message=_("Restore Failed, see System Status Notification for details"); 
    261     return ($Message); 
    262   } else { 
    263     // TODO: put in notification error and add code above to collect details 
    264     //       along the way to put something meaningful in it 
    265     // 
    266     return ($Message); 
    267   } 
    268 
    269 function Get_Backup_Sets() { 
    270         global $db; 
    271         $sql = "SELECT * FROM Backup"; 
    272         $results = $db->getAll($sql); 
    273         if(DB::IsError($results)) { 
    274                 $results = null; 
    275         } 
    276         return $results; 
    277 
    278 function Delete_Backup_Set($ID="") { 
    279         global $db; 
    280   global $asterisk_conf; 
    281   global $amp_conf; 
    282   $sql = "DELETE FROM Backup  WHERE ID = '$ID'"; 
    283         $result = $db->query($sql); 
    284         if(DB::IsError($result)) { 
    285                 die_freepbx($result->getMessage()); 
    286         } 
    287   //$Cron_Script=$asterisk_conf['astvarlibdir']."/bin/retrieve_backup_cron.php"; 
    288   //exec($Cron_Script); 
    289   //TODO: should we check and act on false return 
     96  if($amp_conf['AMPBACKUPSUDO']==true){$sudo='/usr/bin/sudo';}else{$sudo='';}//use sudo if requested - DANGEROUS!!! 
     97  switch($filetype){ 
     98    case 'ALL': 
     99      $fileholder=substr($file, 0,-7); 
     100      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     101      $error = ($error || ($ret != 0)); 
     102   
     103      // First restore voicemial (for some reason if you do it all at once these don't get restored 
     104      exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); 
     105      $error = ($error || ($ret != 0)); 
     106      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | $tar -Pxvz"; 
     107      exec($tar_cmd,$out_arr,$ret); 
     108      $error = ($error || ($ret != 0)); 
     109   
     110      // Next, recordings cause same issue as above 
     111      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | $tar -Pxvz"; 
     112      exec($tar_cmd,$out_arr,$ret); 
     113      $error = ($error || ($ret != 0)); 
     114   
     115      // Now the rest and then we'll get on with the databases 
     116      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | $tar -Pxvz"; 
     117      exec($tar_cmd,$out_arr,$ret); 
     118      $error = ($error || ($ret != 0)); 
     119      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz /tmp/ampbackups.$fileholder/cdr.tar.gz  | $tar -Pxvz"; 
     120      exec($tar_cmd,$out_arr,$ret); 
     121      $error = ($error || ($ret != 0)); 
     122      $tar_cmd="$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/asteriskcdr.sql /tmp/ampbackups.$fileholder/astdb.dump"; 
     123      exec($tar_cmd,$out_arr,$ret); 
     124      $error = ($error || ($ret != 0)); 
     125   
     126      $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql 2>&1"; 
     127      exec($sql_cmd,$out_arr,$ret); 
     128      $error = ($error || ($ret != 0)); 
     129      $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; 
     130      exec($sql_cmd,$out_arr,$ret); 
     131      $error = ($error || ($ret != 0)); 
     132      exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); 
     133      $error = ($error || ($ret != 0)); 
     134       
     135      //restore additional file (aka AMPPROVROOT), using sudo if requested 
     136      $tar_cmd="$sudo $tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/phoneconfig.tar.gz |$sudo $tar -Pxvz"; 
     137      exec($tar_cmd,$out_arr,$ret); 
     138      $error = ($error || ($ret != 0)); 
     139      exec("/bin/rm -rf /tmp/ampbackups.$fileholder",$out_arr,$ret); 
     140      $error = ($error || ($ret != 0)); 
     141      if(!error){$message=_("Restored All Files in BackupSet");} 
     142      break; 
     143    case 'VoiceMail': 
     144      $fileholder=substr($file, 0,-7); 
     145      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     146      $error = ($error || ($ret != 0)); 
     147      exec('/bin/rm -rf '.$amp_conf['ASTSPOOLDIR'].'/voicemail 2>&1',$out_arr,$ret); 
     148      $error = ($error || ($ret != 0)); 
     149      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/voicemail.tar.gz | $tar -Pxvz"; 
     150      exec($tar_cmd,$out_arr,$ret); 
     151      $error = ($error || ($ret != 0)); 
     152      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     153      $error = ($error || ($ret != 0)); 
     154      if(!error){$message=_("Restored VoiceMail");} 
     155    break; 
     156    case 'Recordings': 
     157      $fileholder=substr($file, 0,-7); 
     158      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     159      $error = ($error || ($ret != 0)); 
     160      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/recordings.tar.gz | $tar -Pxvz"; 
     161      exec($tar_cmd,$out_arr,$ret); 
     162      $error = ($error || ($ret != 0)); 
     163      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     164      $error = ($error || ($ret != 0)); 
     165      if(!error){$message=_("Restored System Recordings");} 
     166    break; 
     167    case 'Configurations': 
     168      $fileholder=substr($file, 0,-7); 
     169      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     170      $error = ($error || ($ret != 0)); 
     171      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/configurations.tar.gz | $tar -Pxvz"; 
     172      exec($tar_cmd,$out_arr,$ret); 
     173      $error = ($error || ($ret != 0)); 
     174      $tar_cmd="$$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asterisk.sql /tmp/ampbackups.$fileholder/astdb.dump"; 
     175      exec($tar_cmd,$out_arr,$ret); 
     176      $error = ($error || ($ret != 0)); 
     177      $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asterisk.sql"; 
     178      exec($sql_cmd,$out_arr,$ret); 
     179      $error = ($error || ($ret != 0)); 
     180      exec($amp_conf['AMPBIN']."/restoreastdb.php $fileholder 2>&1",$out_arr,$ret); 
     181      $error = ($error || ($ret != 0)); 
     182      //restore additional file (aka AMPPROVROOT), using sudo if requested 
     183      $tar_cmd="$sudo $tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/phoneconfig.tar.gz |$sudo $tar -Pxvz"; 
     184      exec($tar_cmd,$out_arr,$ret); 
     185       
     186      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     187      $error = ($error || ($ret != 0)); 
     188      if(!error){$message=_("Restored System Configuration");} 
     189    break; 
     190    case 'FOP': 
     191      $fileholder=substr($file, 0,-7); 
     192      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     193      $error = ($error || ($ret != 0)); 
     194      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/fop.tar.gz | $tar -Pxvz"; 
     195      exec($tar_cmd,$out_arr,$ret); 
     196      $error = ($error || ($ret != 0)); 
     197      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     198      $error = ($error || ($ret != 0)); 
     199      if(!error){$message=_("Restored Operator Panel");} 
     200    break; 
     201    case 'CDR': 
     202      $fileholder=substr($file, 0,-7); 
     203      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     204      $error = ($error || ($ret != 0)); 
     205      $tar_cmd="$tar -PxvOz -f \"$dir\" /tmp/ampbackups.$fileholder/cdr.tar.gz | $tar -Pxvz"; 
     206      exec($tar_cmd,$out_arr,$ret); 
     207      $error = ($error || ($ret != 0)); 
     208      $tar_cmd="$tar -Pxvz -f \"$dir\" /tmp/ampbackups.$fileholder/asteriskcdr.sql"; 
     209      exec($tar_cmd,$out_arr,$ret); 
     210      $error = ($error || ($ret != 0)); 
     211      $sql_cmd="mysql -u ".$amp_conf['AMPDBUSER']." -p".$amp_conf['AMPDBPASS']." < /tmp/ampbackups.$fileholder/asteriskcdr.sql 2>&1"; 
     212      exec($sql_cmd,$out_arr,$ret); 
     213      $error = ($error || ($ret != 0)); 
     214      exec("/bin/rm -rf /tmp/ampbackups.$fileholder 2>&1",$out_arr,$ret); 
     215      $error = ($error || ($ret != 0)); 
     216      if(!error){$message=_("Restored CDR logs");} 
     217    break; 
     218  } 
     219  return ($error)?$message:_('Restore Failed, see System Status Notification for details'); 
     220
     221 
     222function backup_get(){ 
     223  global $db; 
     224  $sql = "SELECT * FROM backup ORDER BY name ASC"; 
     225  $results = $db->getAll($sql); 
     226  if(DB::IsError($results)) { 
     227    $results = null; 
     228  } 
     229  return $results; 
     230
     231 
     232function backup_delete_set($id=''){ 
     233  global $db,$asterisk_conf,$amp_conf; 
     234  $sql = "DELETE FROM backup WHERE id =?"; 
     235  $result = $db->query($sql,array($id)); 
     236  if(DB::IsError($result)) { 
     237    die_freepbx($result->getMessage()); 
     238  } 
    290239  backup_retrieve_backup_cron(); 
    291240} 
    292 function Save_Backup_Schedule($Backup_Parms, $backup_options ) 
    293 
    294         global $db; 
    295   global $asterisk_conf; 
    296   global $amp_conf; 
    297   if ($Backup_Parms[1]=="now") 
    298   { 
    299     $Cron_Script=$asterisk_conf['astvarlibdir']."/bin/ampbackup.php '$Backup_Parms[0]' $backup_options[0] $backup_options[1] $backup_options[2] $backup_options[3] $backup_options[4]"; 
    300     //echo "$Cron_Script"; 
    301     /*  
    302      * ***** Next few lines would execute the script nativly, but will show the shebang in the web page ***** 
    303      *      
    304      * $argv=array('', $Backup_Parms[0], $backup_options[0], $backup_options[1], $backup_options[2], $backup_options[3], $backup_options[4]); 
    305      * $argc=count($argv); 
    306      * include($asterisk_conf['astvarlibdir'].'/bin/ampbackup.php') 
    307      */     
    308     exec($Cron_Script); 
    309   } 
    310   $sql = "INSERT INTO Backup (Name, Voicemail, Recordings, Configurations, CDR, FOP, Minutes, Hours, Days, Months,Weekdays, Command, Method ) VALUES ("; 
    311         $sql .= "'".$Backup_Parms[0]."',"; 
    312         $sql .= "'".$backup_options[0]."',"; 
    313         $sql .= "'".$backup_options[1]."',"; 
    314         $sql .= "'".$backup_options[2]."',"; 
    315         $sql .= "'".$backup_options[3]."',"; 
    316         $sql .= "'".$backup_options[4]."',"; 
    317         $sql .= "'".$Backup_Parms[2]."',"; 
    318         $sql .= "'".$Backup_Parms[3]."',"; 
    319         $sql .= "'".$Backup_Parms[4]."',"; 
    320         $sql .= "'".$Backup_Parms[5]."',"; 
    321         $sql .= "'".$Backup_Parms[6]."',"; 
    322         $sql .= "'".$Backup_Parms[7]."',"; 
    323         $sql .= "'".$Backup_Parms[1]."');"; 
    324         $result = $db->query($sql); 
    325         if(DB::IsError($result)) { 
    326                 die_freepbx($result->getMessage().'<hr>'.$sql); 
    327         } 
    328   //$Cron_Script=$asterisk_conf['astvarlibdir']."/bin/retrieve_backup_cron.php"; 
    329   //exec($Cron_Script); 
     241 
     242function backup_save_schedule($parms){ 
     243  global $db,$asterisk_conf,$amp_conf; 
     244  //build query based on the following keys 
     245  $parms_num=array('admin','cdr','command','configurations','days','emailaddr', 
     246                  'emailmaxsize','emailmaxtype','exclude','fop','ftpdir','ftphost', 
     247                  'ftppass','ftpuser','hours','id','include','method','minutes', 
     248                  'months','name','recordings','sshdir','sshhost','sshkey','sshuser', 
     249                  'sudo','voicemail','weekdays'); 
     250  foreach($parms_num as $dprm){$db_parms[$dprm]=isset($parms[$dprm])?$parms[$dprm]:'';} 
     251  $keys=$vals=''; 
     252  //dont include empty values in the query 
     253  foreach(array_keys($db_parms) as $key){ 
     254    if($db_parms[$key]!=''){ 
     255      $keys.=$key.','; 
     256    } 
     257  } 
     258  foreach(array_values($db_parms) as $val){ 
     259    if($val!=''){ 
     260      $vals.='"'.$db->escapeSimple($val).'",'; 
     261    } 
     262  } 
     263  $keys=substr($keys,0,-1);$vals=substr($vals,0,-1); 
     264  $sql='INSERT INTO backup ('.$keys.') VALUES ('.$vals.')'; 
     265  $result = $db->query($sql); 
     266  if(DB::IsError($result)) { 
     267    die_freepbx($result->getMessage().'<hr>'.$sql); 
     268  } 
     269  if($parms['method']=='now' && $result){ 
     270    $latest=$db->getOne('select last_insert_id()'); 
     271    $backup_script=$asterisk_conf['astvarlibdir'].'/bin/ampbackup.php '.$latest; 
     272    exec($backup_script); 
     273  } 
    330274  backup_retrieve_backup_cron(); 
    331275   
    332276} 
    333 function Get_Backup_String($name, $backup_schedule, $ALL_days, $ALL_months, $ALL_weekdays, $mins="", $hours="", $days="", $months="", $weekdays="")
     277function backup_get_string($parms)
    334278  global $asterisk_conf; 
    335   if ($backup_schedule=="hourly") 
    336     $Cron_String="0 * * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    337   else if ($backup_schedule=="daily") 
    338     $Cron_String="0 0 * * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    339   else if ($backup_schedule=="weekly") 
    340     $Cron_String="0 0 * * 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    341   else if ($backup_schedule=="monthly") 
    342     $Cron_String="0 0 1 * * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    343   else if ($backup_schedule=="yearly") 
    344     $Cron_String="0 0 1 1 * ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    345   else if ($backup_schedule=="follow_schedule") 
    346   { 
    347     $mins_string=''; 
    348     $hours_string=''; 
    349     if (count($mins)<1) 
    350             $mins_string=":0:"; 
    351     else{ 
    352       foreach ($mins as $value) 
    353               $mins_string.=":$value:"; 
    354     } 
    355     if (count($hours)<1) 
    356             $hours_string=":0:"; 
    357     else{ 
    358       foreach ($hours as $value) 
    359               $hours_string.=":$value:"; 
    360     } 
    361     if(($ALL_days=="1")||(count($days)<1)) 
    362       $days_string="*"; 
    363     else{ 
    364       foreach ($days as $value) 
    365               $days_string.=":$value:"; 
    366     } 
    367     if(($ALL_months=="1")||(count($months)<1)) 
    368       $months_string="*"; 
    369     else{ 
    370       foreach ($months as $value) 
    371               $months_string.=":$value:"; 
    372     } 
    373     if($ALL_weekdays=="1"||(count($weekdays)<1)) 
    374       $weekdays_string="*"; 
    375     else{ 
    376       foreach ($weekdays as $value) 
    377               $weekdays_string.=":$value:"; 
    378     } 
    379     $cron_mins_string=trim($mins_string,":"); 
    380     $cron_hours_string=trim($hours_string,":"); 
    381     $cron_days_string=trim($days_string,":"); 
    382     $cron_months_string=trim($months_string,":"); 
    383     $cron_weekdays_string=trim($weekdays_string,":"); 
    384     $Cron_String=str_replace("::", ",", "$cron_mins_string $cron_hours_string $cron_days_string $cron_months_string $cron_weekdays_string ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"); 
    385   } 
    386   else if ($backup_schedule=="now") 
    387   $Cron_String="0 0 0 0 0 ".$asterisk_conf['astvarlibdir']."/bin/ampbackup.php"; 
    388   $Backup_String[]=$name; 
    389   $Backup_String[]=$backup_schedule; 
    390   $Backup_String[]=isset($mins_string)?$mins_string:''; 
    391   $Backup_String[]=isset($hours_string)?$hours_string:''; 
    392   $Backup_String[]=isset($days_string)?$days_string:''; 
    393   $Backup_String[]=isset($months_string)?$months_string:''; 
    394   $Backup_String[]=isset($weekdays_string)?$weekdays_string:''; 
    395   $Backup_String[]=$Cron_String; 
    396  
    397   return ($Backup_String); 
    398 
    399 function Get_Backup_Times($BackupID) 
    400 
    401         global $db; 
    402         $sql = "SELECT Minutes, Hours, Days, Months, Weekdays, Method From Backup where ID=\"$BackupID\""; 
    403         $results = $db->getAll($sql); 
    404         if(DB::IsError($results)) { 
    405                 $results = Array(null, null, null, null, null, null); 
    406         } 
    407         return $results; 
    408 
    409 function Get_Backup_Options($BackupID) 
    410 
    411         global $db; 
    412         $sql = "SELECT Name, Voicemail, Recordings, Configurations, CDR, FOP FROM Backup where ID=\"$BackupID\""; 
    413         $results = $db->getAll($sql); 
    414         if(DB::IsError($results)) { 
    415                 $results = Array(null, null, null, null, null, null); 
    416         } 
    417         return $results; 
    418 
    419 function Show_Backup_Options($ID="") 
    420 
     279  switch($parms['backup_schedule']){ 
     280    case 'hourly': 
     281      $cron_string='0 * * * * '; 
     282    break; 
     283    case 'daily': 
     284      $cron_string='0 0 * * * '; 
     285    break; 
     286    case 'weekly': 
     287      $cron_string='0 0 * * 0 '; 
     288    break; 
     289    case 'monthly': 
     290      $cron_string='0 0 1 * * '; 
     291    break; 
     292    case 'yearly': 
     293      $cron_string='0 0 1 1 * '; 
     294    break; 
     295    case 'now': 
     296      $cron_string='0 0 0 0 0 '; 
     297    break; 
     298    case 'follow_schedule': 
     299      $mins_string=$hours_string=$days_string=$months_string=$weekdays_string=''; 
     300      if(is_array($parms['mins'])){ 
     301        foreach($parms['mins'] as $value){ 
     302          $mins_string.=":$value:"; 
     303        } 
     304      }else{ 
     305        $mins_string=":0:"; 
     306      } 
     307      if(is_array($parms['hours'])){ 
     308        foreach($parms['hours'] as $value){ 
     309          $hours_string.=":$value:"; 
     310        } 
     311      }else{ 
     312        $hours_string=":0:"; 
     313      } 
     314      if(isset($parms['all_days']) && $parms['all_days']=='0'){ 
     315        foreach($parms['days'] as $value){ 
     316          $days_string.=":$value:"; 
     317        } 
     318      }else{ 
     319        $days_string="*"; 
     320      } 
     321      if(isset($parms['all_months']) && $parms['all_months']=='0'){ 
     322        foreach($parms['months'] as $value){ 
     323          $months_string.=":$value:"; 
     324        } 
     325      }else{ 
     326        $months_string="*"; 
     327      } 
     328      if(isset($parms['all_weekdays']) && $parms['all_weekdays']=='0'){ 
     329        foreach($parms['weekdays'] as $value){ 
     330         $weekdays_string.=":$value:"; 
     331        } 
     332      }else{ 
     333        $weekdays_string="*"; 
     334      } 
     335      $cron_mins_string=trim($mins_string,":"); 
     336      $cron_hours_string=trim($hours_string,":"); 
     337      $cron_days_string=trim($days_string,":"); 
     338      $cron_months_string=trim($months_string,":"); 
     339      $cron_weekdays_string=trim($weekdays_string,":"); 
     340      $cron_string=str_replace("::", ",", "$cron_mins_string $cron_hours_string $cron_days_string $cron_months_string $cron_weekdays_string"); 
     341    break; 
     342  } 
     343  $backup_string['name']=$parms['name']; 
     344  $backup_string['method']=$parms['backup_schedule']; 
     345  $backup_string['minutes']=isset($mins_string)?$mins_string:''; 
     346  $backup_string['hours']=isset($hours_string)?$hours_string:''; 
     347  $backup_string['days']=isset($days_string)?$days_string:''; 
     348  $backup_string['months']=isset($months_string)?$months_string:''; 
     349  $backup_string['weekdays']=isset($weekdays_string)?$weekdays_string:''; 
     350  $backup_string['command']=$cron_string.' '.$asterisk_conf['astvarlibdir'].'/bin/ampbackup.php'; 
     351  $ret=array_merge($parms,$backup_string); 
     352  return ($ret); 
     353
     354function Get_Backup_Times($id){ 
     355  global $db; 
     356  $sql = "SELECT minutes, hours, days, months, weekdays, method From backup where id=?"; 
     357  $results = $db->getAll($sql,array($id)); 
     358  if(DB::IsError($results)) { 
     359    $results = Array(null, null, null, null, null, null); 
     360  } 
     361  return $results; 
     362
     363function Get_Backup_Options($id){ 
     364  global $db; 
     365  $sql = "SELECT * FROM backup WHERE id=?"; 
     366  $results = $db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); 
     367  if(DB::IsError($results)) { 
     368    $results = Array(null, null, null, null, null, null); 
     369  } 
     370  return $results[0]; 
     371
     372function backup_showopts($id=''){ 
    421373  $tabindex=0; 
    422   if ($ID==""){ 
    423     $name=""; $voicemail="no"; $sysrecordings="no"; $sysconfig="no"; $cdr="no"; $fop="no";} 
    424   else{ 
    425     $backup_options=Get_Backup_Options($ID); 
    426     foreach ($backup_options as $bk_options)  
    427       $name="$bk_options[0]";$voicemail="$bk_options[1]"; $sysrecordings="$bk_options[2]"; $sysconfig="$bk_options[3]"; $cdr="$bk_options[4]"; $fop="$bk_options[5]"; 
     374  if ($id==''){ 
     375    $opts=array('name','voicemail','recordings','configurations','cdr','fop'); 
     376    foreach($opts as $o){$opts[$o]='';}//set defaults to '' 
     377  }else{ 
     378    $opts=Get_Backup_Options($id); 
    428379  } 
    429380  ?> 
    430         <tr> 
    431                 <td><a href="#" class="info"><?php echo _("Schedule Name:")?><span><?php echo _("Give this Backup Schedule a brief name to help you identify it.");?></span></a></td> 
    432                 <td><input type="text" name="name" value="<?php echo (isset($name) ? $name : ''); ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
    433         </tr> 
    434  
     381  <table> 
     382  <tr><td colspan="2"><h5><?php echo _("Basic Settings")?><hr></h5></td></tr> 
     383  <tr> 
     384      <td><a href="#" class="info"><?php echo _("Schedule Name:")?><span><?php echo _("Give this Backup Schedule a brief name to help you identify it.");?></span></a></td> 
     385      <td><input type="text" name="name" value="<?php echo (isset($opts['name'])?$opts['name']:''); ?>" tabindex="<?php echo ++$tabindex;?>"></td> 
     386  </tr> 
    435387  <tr> 
    436388    <td><a href="#" class="info"><?php echo _("VoiceMail");?><span><?php echo _("Backup the System VoiceMail Boxes... CAUTION: Could result in large file");?></span></a>: </td> 
    437     <?php if ($voicemail == "yes"){?> 
    438       <td><input type="radio" name="bk_voicemail"  tabindex="<?php echo ++$tabindex;?>" value="yes" checked=checked /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_voicemail" value="no"/> <?php echo _("no");?></td> 
    439     <?php } else{ ?> 
    440       <td><input type="radio" name="bk_voicemail"  tabindex="<?php echo ++$tabindex;?>" value="yes" /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_voicemail" value="no" checked=checked/> <?php echo _("no");?></td> 
    441     <?php } ?> 
     389    <td><input type="checkbox" name="voicemail"  tabindex="<?php echo ++$tabindex;?>" value="yes" <?php echo ($opts['voicemail']=='yes')?'checked':''; ?> /></td> 
    442390  </tr> 
    443391  <tr> 
    444     <td><a href="#" class="info"><?php echo _("System Recordings");?><span><?php echo _("Backup the System Recordings (AutoAttendant, Music On Hold, System Recordings)");?></span></a>: </td> 
    445     <?php if ($sysrecordings == "yes"){?> 
    446       <td><input type="radio" name="bk_sysrecordings" value="yes" checked=checked/> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_sysrecordings" value="no"/> <?php echo _("no");?></td> 
    447     <?php } else{ ?> 
    448       <td><input type="radio" name="bk_sysrecordings" value="yes" /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_sysrecordings" value="no" checked=checked/> <?php echo _("no");?></td> 
    449     <?php } ?> 
     392    <td><a href="#" class="info"><?php echo _("System Recordings");?><span><?php echo _("Backup the System Recordings (AutoAttendent, Music On Hold, System Recordings)");?></span></a>: </td> 
     393    <td><input type="checkbox" name="recordings" value="yes" <?php echo ($opts['recordings']=='yes')?'checked':''; ?> /></td> 
    450394  </tr> 
    451395  <tr> 
    452396    <td><a href="#" class="info"><?php echo _("System Configuration");?><span><?php echo _("Backup the System Configurations (Database, etc files, SQL Database, astdb)");?></span></a>: </td> 
    453     <?php if ($sysconfig == "yes"){?
    454      <td><input type="radio" name="bk_sysconfig" value="yes" checked=checked/> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_sysconfig" value="no"/> <?php echo _("no");?></td
    455   <?php } else{ ?
    456     <td><input type="radio" name="bk_sysconfig" value="yes" /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_sysconfig" value="no" checked=checked/> <?php echo _("no");?></td> 
    457     <?php } ?
     397    <td><input type="checkbox" name="configurations" value="yes" <?php echo ($opts['configurations']=='yes')?'checked':''; ?>/></td
     398  </tr
     399  <tr
     400    <td><a href="#" class="info"><?php echo _("Admin Web Directory");?><span><?php echo _("Backup the admin web directory (i.e. the static FreePBX web files). This is usefull to have durring a restore to prevent a version mismatch, but can baloon the backup size.");?></span></a>: </td> 
     401    <td><input type="checkbox" name="admin" value="yes" <?php echo ($opts['admin']=='yes')?'checked':''; ?>/></td
    458402  </tr> 
    459403  <tr> 
    460404    <td><a href="#" class="info"><?php echo _("CDR");?><span><?php echo _("Backup the System Call Detail Reporting (HTML and Database)");?></span></a>: </td> 
    461     <?php if ($cdr == "yes"){?> 
    462       <td><input type="radio" name="bk_cdr" value="yes" checked=checked/> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_cdr" value="no"/> <?php echo _("no");?></td> 
    463     <?php } else{ ?> 
    464       <td><input type="radio" name="bk_cdr" value="yes" /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_cdr" value="no" checked=checked/> <?php echo _("no");?></td> 
    465     <?php } ?> 
     405    <td><input type="checkbox" name="cdr" value="yes" <?php echo ($opts['cdr']=='yes')?'checked':''; ?>/></td> 
    466406  </tr> 
    467407  <tr> 
    468408    <td><a href="#" class="info"><?php echo _("Operator Panel");?><span><?php echo _("Backup the Operator Panel (HTML and Database)");?></span></a>: </td> 
    469     <?php if ($fop == "yes"){?> 
    470       <td><input type="radio" name="bk_fop" value="yes" checked=checked/> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_fop" value="no"/> <?php echo _("no");?></td> 
    471     <?php } else{ ?> 
    472       <td><input type="radio" name="bk_fop" value="yes" /> <?php echo _("yes");?> &nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="bk_fop" value="no" checked=checked/> <?php echo _("no");?></td> 
    473     <?php } ?> 
    474   </tr> 
     409    <td><input type="checkbox" name="fop" value="yes" <?php echo ($opts['fop']=='yes')?'checked':''; ?>/></td> 
     410  </tr> 
     411 
     412  <tr><td colspan="2"><h5><span class="tog files">+</span><?php echo _(' Additonal Files')?><hr></h5></td></tr> 
     413  <tr class="hide files"> 
     414    <td><a href="#" class="info"><?php echo _("Additional files and folders");?><span><?php echo _("Backup any additional files and folders listed here.");?></span></a>: </td> 
     415    <td><textarea name="include" /><?php echo $opts['include']; ?></textarea></td> 
     416  </tr> 
     417  <tr class="hide files"> 
     418    <td><a href="#" class="info"><?php echo _("Exclude files and folders");?><span><?php echo _("Exclude any  files and folders from the include listed above.");?></span></a>: </td> 
     419    <td><textarea name="exclude" /><?php echo $opts['exclude']; ?></textarea></td> 
     420  </tr> 
     421   
     422  <tr><td colspan="2"><h5><span class="tog ftp">+</span><?php echo _(' FTP Settings')?><hr></h5></td></tr> 
     423  <tr class="hide ftp"> 
     424    <td><a href="#" class="info"><?php echo _("Ftp User Name");?><span><?php echo _('');?></span></a>: </td> 
     425    <td><input type="text" name="ftpuser" value="<?php echo $opts['ftpuser']; ?>" /></td> 
     426  </tr> 
     427  <tr class="hide ftp"> 
     428    <td><a href="#" class="info"><?php echo _("Ftp Password");?><span><?php echo _('');?></span></a>: </td> 
     429    <td><input type="text" name="ftppass" value="<?php echo $opts['ftppass']; ?>" /></td> 
     430  </tr> 
     431  <tr class="hide ftp"> 
     432    <td><a href="#" class="info"><?php echo _("Ftp Hostname");?><span><?php echo _('IP address or FQDN of FTP server');?></span></a>: </td> 
     433    <td><input type="text" name="ftphost" value="<?php echo $opts['ftphost']; ?>" /></td> 
     434  </tr> 
     435  <tr class="hide ftp"> 
     436    <td><a href="#" class="info"><?php echo _("Ftp Directory");?><span><?php echo _('Directory on FTP server where the backup should be copied to');?></span></a>: </td> 
     437    <td><input type="text" name="ftpdir" value="<?php echo $opts['ftpdir']; ?>" /></td> 
     438  </tr> 
     439  <tr><td colspan="2"><h5><span class="tog ssh">+</span><?php echo _(' SSH Settings')?><hr></h5></td></tr> 
     440  <tr class="hide ssh"> 
     441    <td><a href="#" class="info"><?php echo _("SSH User Name");?><span><?php echo _('');?></span></a>: </td> 
     442    <td><input type="text" name="sshuser" value="<?php echo $opts['sshuser']; ?>" /></td> 
     443  </tr> 
     444  <tr class="hide ssh"> 
     445    <td><a href="#" class="info"><?php echo _("SSH Key");?><span><?php echo _('Location of ssh private key to be used when connect to hossst');?></span></a>: </td> 
     446    <td><input type="text" name="sshkey" value="<?php echo $opts['sshkey']; ?>" /></td> 
     447  </tr> 
     448  <tr class="hide ssh"> 
     449    <td><a href="#" class="info"><?php echo _("SSH Hostname");?><span><?php echo _('IP address or FQDN of remote ssh host');?></span></a>: </td> 
     450    <td><input type="text" name="sshhost" value="<?php echo $opts['sshhost']; ?>" /></td> 
     451  </tr> 
     452  <tr class="hide ssh"> 
     453    <td><a href="#" class="info"><?php echo _("SSH Directory");?><span><?php echo _('Directory on remote server where the backup should be copied t');?></span></a>: </td> 
     454    <td><input type="text" name="sshdir" value="<?php echo $opts['sshdir']; ?>" /></td> 
     455  </tr>  
     456  <tr><td colspan="2"><h5><span class="tog email">+</span><?php echo _(' Email Settings')?><hr></h5></td></tr> 
     457  <tr class="hide email"> 
     458    <td><a href="#" class="info"><?php echo _("Email Address");?><span><?php echo _('Email address where backups should be emailed to');?></span></a>: </td> 
     459    <td><input type="text" name="emailaddr" value="<?php echo $opts['emailaddr']; ?>" /></td> 
     460  </tr>  
     461  <tr class="hide email"> 
     462    <td><a href="#" class="info"><?php echo _("Max email size");?><span><?php echo _('The maximum size a backup can be and still be emailed. Some email servers limit the size of email atttachments, this will make sure that files larger than the max size are not sent. Valid options include: xB, xKB, xMB');?></span></a>: </td> 
     463    <td><select name="emailmaxsize"> 
     464        <?php if($opts['emailmaxsize']==''){$opts['emailmaxsize']=25;}//default max email size to 25 
     465         for($i=1;$i<21;$i++){    echo '<option value="'.$i.'" '.($opts['emailmaxsize']==$i?'selected':'').' >'.$i.'</option>';} 
     466         for($i=25;$i<51;$i+=5){  echo '<option value="'.$i.'" '.($opts['emailmaxsize']==$i?'selected':'').' >'.$i.'</option>';} 
     467         for($i=60;$i<101;$i+=10){echo '<option value="'.$i.'" '.($opts['emailmaxsize']==$i?'selected':'').' >'.$i.'</option>';}?> 
     468        </select> 
     469        <select name="emailmaxtype"> 
     470        <?php if($opts['emailmaxtype']==''){$opts['emailmaxtype']='MB';}//default max type to MB 
     471         $maxtypes=array('B','KB','MB'); 
     472        foreach($maxtypes as $max){echo '<option value="'.$max.'" '.($opts['emailmaxtype']==$max?'selected':'').' >'.$max.'</option>';  } ?> 
     473      </select> 
     474      </td> 
     475  </tr> 
     476  <style type="text/css"> 
     477  .tog{cursor:pointer;color:black} 
     478  .hide{display:none} 
     479  h5{margin-top:10px;margin-bottom:10px} 
     480  </style> 
     481  <script language="javascript" type="text/javascript"> 
     482    $(document).ready(function() { 
     483      $('.tog').click(function(){ 
     484        var tclass = $(this).attr('class'); tclass = tclass.replace('tog ', ''); 
     485        if($(this).text()=='+'){ 
     486          $(this).text('- '); 
     487          $('.'+tclass).show(); 
     488        }else{ 
     489          $(this).text('+'); 
     490          $('.'+tclass).not('.tog').hide(); 
     491        } 
     492 
     493       }) 
     494    }); 
     495 
     496  </script> 
     497 
     498 
    475499  <?php 
    476500} 
    477 function Schedule_Show_Minutes($Minutes_Set="") 
    478 
     501function Schedule_Show_Minutes($Minutes_Set=""){ 
    479502  echo "<br><br><table> <tr>"; 
    480503  echo "<td valign=top><select multiple size=12 name=mins[]>"; 
    481   for ($minutes=0; $minutes<=59; $minutes++) 
    482   { 
    483 /*    if (($minutes==12)||($minutes==24)||($minutes==36)||($minutes==48)) 
    484     { 
    485       echo "</select></td>"; 
    486       echo "<td width=2 valign=top><select multiple size=12 name=mins[]>"; 
    487     } 
    488 */    if (strstr($Minutes_Set,":$minutes:")) 
     504  for ($minutes=0; $minutes<=59; $minutes++){ 
     505/* if (($minutes==12)||($minutes==24)||($minutes==36)||($minutes==48)) { echo  
     506"</select></td>"; echo "<td width=2 valign=top><select multiple size=12  
     507name=mins[]>"; } */  
     508    if (strstr($Minutes_Set,":$minutes:")) 
    489509      echo "<option value=\"$minutes\" selected>$minutes"; 
    490510    else 
     
    494514  echo "</tr></table></td>"; 
    495515} 
    496 function Schedule_Show_Hours($Hours_Set="") 
    497 
     516function Schedule_Show_Hours($Hours_Set=""){ 
    498517  echo "<br><br><table> <tr>"; 
    499518  echo "<td valign=top><select multiple size=12 name=hours[]>"; 
    500519  for ($hours=0; $hours<=23; $hours++) 
    501520  { 
    502 /*    if ($hours==12) 
    503     { 
    504       echo "</select></td>"; 
    505       echo "<td valign=top><select multiple size=12 name=hours[]>"; 
    506     } 
    507 */    if (strstr($Hours_Set,":$hours:")) 
     521  /* if ($hours==12) { echo "</select></td>"; echo "<td valign=top><select multiple size=12 name=hours[]>"; } */  
     522    if (strstr($Hours_Set,":$hours:")) 
    508523      echo "<option value=\"$hours\" selected>$hours"; 
    509524    else 
     
    514529} 
    515530 
    516 function Schedule_Show_Days($Days_Set="") 
    517 
     531function Schedule_Show_Days($Days_Set=""){ 
    518532  if (($Days_Set=="") || ($Days_Set=="*")){ 
    519533  echo "<input type=radio name=all_days value=1 checked>"; echo _("All"); echo "<br>"; 
     
    529543  for ($days=1; $days<=31; $days++) 
    530544  { 
    531 /*    if (($days==13)||($days==25)) 
    532     { 
    533       echo "</select></td>"; 
    534       echo "<td valign=top><select multiple size=12 name=days[]>"; 
    535     } 
    536 */    if ((strstr($Days_Set,":$days:")) || ($Days_Set=="*")) 
     545/* if (($days==13)||($days==25)) { echo "</select></td>"; echo "<td valign=top><select multiple size=12 name=days[]>"; } */  
     546  if ((strstr($Days_Set,":$days:"))|| ($Days_Set=="*")) 
    537547      echo "<option value=\"$days\" selected>$days"; 
    538548    else 
     
    543553} 
    544554 
    545 function Schedule_Show_Months($Months_Set="") 
    546 
     555function Schedule_Show_Months($Months_Set=""){ 
    547556  if (($Months_Set=="") || ($Months_Set=="*")){ 
    548557  echo "<input type=radio name=all_months value=1 checked>"; echo _("All"); echo "<br>"; 
     
    572581} 
    573582 
    574 function Schedule_Show_Weekdays($Weekdays_Set="") 
    575 
     583function Schedule_Show_Weekdays($Weekdays_Set=""){ 
    576584  if (($Weekdays_Set=="") || ($Weekdays_Set=="*")){ 
    577585  echo "<input type=radio name=all_weekdays value=1 checked>";echo _("All"); echo "<br>"; 
     
    595603  echo "</tr></table></td>"; 
    596604} 
    597 function show_quickbar($Method="") 
    598 
     605function show_quickbar($method=''){ 
    599606?> 
    600607  <tr bgcolor=#b7b7b7> <td colspan=6><?php echo _("Run Backup");?>  
    601608  <select name=backup_schedule> 
    602   <option value=follow_schedule <?php echo ($Method == "follow_schedule" ? "SELECTED" : "")?>><?php echo _("Follow Schedule Below");?> 
    603   <option value=now <?php echo ($Method == "now" ? "SELECTED" : "")?>><?php echo _("Now");?> 
    604   <option value=daily <?php echo ($Method == "daily" ? "SELECTED" : "")?>><?php echo _("Daily (at midnight)");?> 
    605   <option value=weekly <?php echo ($Method == "weekly" ? "SELECTED" : "")?>><?php echo _("Weekly (on Sunday)");?> 
    606   <option value=monthly <?php echo ($Method == "monthly" ? "SELECTED" : "")?>><?php echo _("Monthly (on the 1st)");?> 
    607   <option value=yearly <?php echo ($Method == "yearly" ? "SELECTED" : "")?>><?php echo _("Yearly (on 1st Jan)");?> 
     609  <option value=follow_schedule <?php echo ($method=="follow_schedule"?"SELECTED":'')?>><?php echo _("Follow Schedule Below");?> 
     610  <option value=now <?php echo ($method=="now"?"SELECTED":'')?>><?php echo _("Now");?> 
     611  <option value=daily <?php echo ($method=="daily"?"SELECTED":'')?>><?php echo _("Daily (at midnight)");?> 
     612  <option value=weekly <?php echo ($method=="weekly"?"SELECTED":'')?>><?php echo _("Weekly (on Sunday)");?> 
     613  <option value=monthly <?php echo ($method=="monthly"?"SELECTED":'')?>><?php echo _("Monthly (on the 1st)");?> 
     614  <option value=yearly <?php echo ($method=="yearly"?"SELECTED":'')?>><?php echo _("Yearly (on 1st Jan)");?> 
    608615  </select> 
    609616  </td></tr> 
    610617<?php 
    611618} 
    612 function show_schedule($quickbar="no", $BackupID="") 
    613 
     619function show_schedule($quickbar="no", $BackupID=""){ 
    614620  if ($BackupID==""){ 
    615621    $Minutes=""; 
     
    619625    $Weekdays=""; 
    620626    $Method="follow_schedule"; 
    621   } 
    622   else{ 
     627  }else{ 
    623628    $backup_times=Get_Backup_Times($BackupID); 
    624629    foreach ($backup_times as $bk_times)  
     
    647652  Schedule_Show_Weekdays($Weekdays); 
    648653} 
    649