示例#1
0
function restore_forms()
{
    $mainframe =& JFactory::getApplication();
    $database =& JFactory::getDBO();
    jimport('joomla.utilities.error');
    jimport('joomla.filesystem.file');
    $files = $_FILES;
    if (is_array($files) && !empty($files)) {
        //the file has been uploaded
        $file = $files['file'];
        $filename = $file['name'];
        $exten = explode(".", $filename);
        if ($exten[count($exten) - 1] == 'cf4bak') {
            $path = JPATH_BASE . DS . 'cache';
            $uploadedfile = JFile::upload($file['tmp_name'], $path . DS . $filename);
            if (!$uploadedfile) {
                JError::raiseWarning(100, "UPLAOD FAILED" . ": " . $file['error']);
                $mainframe->redirect("index.php?option=com_chronoforms");
            } else {
                $data = file_get_contents($path . DS . $filename);
                //preg_match_all('/<__FORM_START__>(.*?)<__FORM_END__>/is', $data, $forms_data);
                $data = trim($data);
                $forms_data = explode("\n", $data);
                if (!empty($forms_data)) {
                    //loop through each form backup line
                    foreach ($forms_data as $form_data) {
                        $form_data = str_replace(array('<__FORM_START__>', '<__FORM_END__>'), '', $form_data);
                        //get form row data
                        $form_row_data = explode('<__FORM_ROW_END__>', $form_data);
                        //get actions data string with tags
                        $form_actions_data = $form_row_data[1];
                        //get form pure row code
                        $form_row_data = str_replace('<__FORM_ROW_START__>', '', $form_row_data[0]);
                        //decrypt the code and save it
                        $form_row_data = unserialize(base64_decode($form_row_data));
                        unset($form_row_data['id']);
                        $row = JTable::getInstance('chronoforms', 'Table');
                        if (!$row->bind($form_row_data)) {
                            JError::raiseWarning(100, $row->getError());
                        }
                        if (!$row->store()) {
                            JError::raiseWarning(100, $row->getError());
                        }
                        $chronoform_id = $row->id;
                        //get form actions rows pure code
                        $form_actions_data = str_replace(array('<__FORM_ACTIONS_START__>', '<__FORM_ACTIONS_END__>'), '', $form_actions_data);
                        //decrypt the code and save it
                        $form_actions_data = unserialize(base64_decode($form_actions_data));
                        foreach ($form_actions_data as $form_action) {
                            unset($form_action['id']);
                            $form_action['chronoform_id'] = $chronoform_id;
                            $row = JTable::getInstance('chronoformactions', 'Table');
                            if (!$row->bind($form_action)) {
                                JError::raiseWarning(100, $row->getError());
                            }
                            if (!$row->store()) {
                                JError::raiseWarning(100, $row->getError());
                            }
                        }
                    }
                }
                //print_r2($forms_data);
                /*if(isset($forms_data[1]) && !empty($forms_data[1])){
                			foreach($forms_data[1] as $k => $form){
                				//extract form row data
                				preg_match('/<__FORM_ROW_START__>(.*?)<__FORM_ROW_END__>/is', $form, $form_row_data);
                				if(isset($form_row_data[1]) && !empty($form_row_data[1])){
                					$form_row_data = unserialize(base64_decode($form_row_data[1]));
                					unset($form_row_data['id']);
                					$row = JTable::getInstance('chronoforms', 'Table');
                					if(!$row->bind($form_row_data)){
                						JError::raiseWarning(100, $row->getError());
                					}
                					if(!$row->store()){
                						JError::raiseWarning(100, $row->getError());
                					}
                					$chronoform_id = $row->id;
                				}
                				//extract form actions data
                				preg_match('/<__FORM_ACTIONS_START__>(.*?)<__FORM_ACTIONS_END__>/is', $form, $form_actions_data);
                				if(isset($form_actions_data[1]) && !empty($form_actions_data[1])){
                					$form_actions_data = unserialize(base64_decode($form_actions_data[1]));
                					foreach($form_actions_data as $form_action){
                						unset($form_action['id']);
                						$form_action['chronoform_id'] = $chronoform_id;
                						$row = JTable::getInstance('chronoformactions', 'Table');
                						if(!$row->bind($form_action)){
                							JError::raiseWarning(100, $row->getError());
                						}
                						if(!$row->store()){
                							JError::raiseWarning(100, $row->getError());
                						}
                					}
                				}
                			}
                		}*/
                $mainframe->redirect("index.php?option=com_chronoforms", "Forms restored successfully.");
            }
        } else {
            //wrong file extension
            JError::raiseWarning(100, "The file uploaded was not a Chronoforms V4 forms backup file.");
            $mainframe->redirect("index.php?option=com_chronoforms");
        }
    } else {
        //no file, render the upload page
        HTML_Admin_ChronoForms::restore_forms();
    }
}
示例#2
0
 function restore_forms()
 {
     $mainframe =& JFactory::getApplication();
     $database =& JFactory::getDBO();
     jimport('joomla.utilities.error');
     jimport('joomla.filesystem.file');
     $files = $_FILES;
     if (is_array($files) && !empty($files)) {
         //the file has been uploaded
         $file = $files['file'];
         $filename = $file['name'];
         $exten = explode(".", $filename);
         if ($exten[count($exten) - 1] == 'cf4bak') {
             $path = JPATH_BASE . DS . 'cache';
             $uploadedfile = JFile::upload($file['tmp_name'], $path . DS . $filename);
             if (!$uploadedfile) {
                 JError::raiseWarning(100, "UPLAOD FAILED" . ": " . $file['error']);
                 $mainframe->redirect("index.php?option=com_chronoforms");
             } else {
                 ChronoFormsAdmin::restore_forms_from_file($path . DS . $filename);
                 $mainframe->redirect("index.php?option=com_chronoforms", "Forms restored successfully.");
             }
         } else {
             //wrong file extension
             JError::raiseWarning(100, "The file uploaded was not a Chronoforms V4 forms backup file.");
             $mainframe->redirect("index.php?option=com_chronoforms");
         }
     } else {
         //no file, render the upload page
         HTML_Admin_ChronoForms::restore_forms();
     }
 }