Пример #1
0
/**
 * @version $Id$
 * @author Adam Morton
 * @author Steven Levin
 */
function archive($formId = NULL)
{
    if (!isset($formId)) {
        $message = dgettext('phatform', 'No form ID was passed');
        return new PHPWS_Error('phatform', 'archive()', $message, 'continue', PHAT_DEBUG_MODE);
    }
    $archiveDir = PHPWS_HOME_DIR . 'files/phatform/archive/';
    $path = $archiveDir;
    clearstatcache();
    if (!is_dir($path)) {
        if (is_writeable($archiveDir)) {
            PHPWS_File::makeDir($path);
        } else {
            return PHPWS_Error::get(PHATFORM_ARCHIVE_PATH, 'phatform', 'Archive.php::archive', $path);
        }
    } else {
        if (!is_writeable($path)) {
            return PHPWS_Error::get(PHATFORM_ARCHIVE_PATH, 'phatform', 'Archive.php::archive()');
        }
    }
    $table = array();
    $time = time();
    $table[] = 'mod_phatform_forms';
    $table[] = 'mod_phatform_forms_seq';
    $table[] = 'mod_phatform_form_' . $formId;
    $table[] = 'mod_phatform_form_' . $formId . '_seq';
    $table[] = 'mod_phatform_multiselect';
    $table[] = 'mod_phatform_multiselect_seq';
    $table[] = 'mod_phatform_checkbox';
    $table[] = 'mod_phatform_checkbox_seq';
    $table[] = 'mod_phatform_dropbox';
    $table[] = 'mod_phatform_dropbox_seq';
    $table[] = 'mod_phatform_options';
    $table[] = 'mod_phatform_options_seq';
    $table[] = 'mod_phatform_radiobutton';
    $table[] = 'mod_phatform_radiobutton_seq';
    $table[] = 'mod_phatform_textarea';
    $table[] = 'mod_phatform_textarea_seq';
    $table[] = 'mod_phatform_textfield';
    $table[] = 'mod_phatform_textfield_seq';
    $step1 = explode('//', PHPWS_DSN);
    $step2 = explode('@', $step1[1]);
    $step3 = explode(':', $step2[0]);
    $step4 = explode('/', $step2[1]);
    $dbuser = $step3[0];
    $dbpass = $step3[1];
    $dbhost = $step4[0];
    $dbname = $step4[1];
    for ($i = 0; $i < sizeof($table); $i++) {
        $pipe = ' >> ';
        if ($i == 0) {
            $pipe = ' > ';
        }
        $goCode = 'mysqldump -h' . $dbhost . ' -u' . $dbuser . ' -p' . $dbpass . ' ' . $dbname . ' ' . $table[$i] . $pipe . $path . $formId . '.' . $time . '.phat';
        system($goCode);
    }
}
        if ($GLOBALS['core']->query("ALTER TABLE mod_xwysiwyg_areas_seq RENAME {$GLOBALS['core']->tbl_prefix}mod_xw_areas_seq", TRUE)) {
            $update = $update + 8;
        }
    } else {
        $update = $update + 8;
    }
    if ($GLOBALS['core']->query("DROP TABLE mod_xwysiwyg_conf", TRUE)) {
        $update = $update + 16;
    }
    /* Create files/xwysiwyg directory */
    if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/")) {
        PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/");
    }
    /* Create files/xwysiwyg/editors directory */
    if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/editors/")) {
        PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/editors/");
    }
    if ($update >= 31) {
        $content .= "Altered database-scheme.<br />";
        $content .= "New module-layout.<br />";
        $content .= "More Settings.<br /><br />";
    } else {
        $content .= "Boost failed to update or alter tables. <br /><br />";
        $status = 0;
    }
}
if (version_compare($currentVersion, "0.4.1") < 0) {
    @unlink(PHPWS_HOME_DIR . "files/xwysiwyg/editors/list.txt");
    $content .= "Xwysiwyg Updates (Version 0.4.1)<br />";
    $content .= "+ Bugfix in manager<br /><br />";
}
 function manageEditors()
 {
     if ($_SESSION["OBJ_user"]->allow_access("xwysiwyg", "settings")) {
         $this->content .= "<a href=\"" . $this->linkRef . "&amp;action=admin" . "\">" . $_SESSION['translate']->it("Back to administration") . "</a>";
         if (isset($_GET['updList'])) {
             //to update, simply delete the existing file
             @unlink(PHPWS_HOME_DIR . "files/xwysiwyg/editors/list.txt");
         }
         $editors = array();
         $formTags = array();
         $table = array();
         $this->content .= "<br /><br /><b>" . $_SESSION['translate']->it("Available editors") . "</b>";
         $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Status") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>");
         $dir = PHPWS_File::readDirectory(PHPWS_HOME_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('conf'));
         if (is_array($dir)) {
             $location = $_SESSION['translate']->it("local");
             foreach ($dir as $file) {
                 include PHPWS_HOME_DIR . "files/xwysiwyg/editors/" . $file;
                 $editors[] = $cfg_editor;
                 $result = $GLOBALS['core']->quickFetch("SELECT editor FROM mod_xw_config WHERE editor = '{$cfg_editor}'", TRUE, TRUE);
                 if ($result) {
                     $status = $_SESSION['translate']->it("installed");
                     $action_link = $this->linkRef . "&amp;action=delEditor&amp;delEditor={$cfg_editor}";
                     $action_label = $_SESSION['translate']->it("Uninstall");
                     $action = "<a href=\"{$action_link}\">{$action_label}</a>";
                     $select = $GLOBALS['core']->quickFetch("SELECT editor FROM mod_xw_editor", TRUE, TRUE);
                     if ($select['editor'] == $cfg_editor) {
                         $editor = "<strong>{$cfg_editor}</strong>";
                     } else {
                         $action_link = $this->linkRef . "&amp;action=toggle&amp;editor={$cfg_editor}";
                         $action_label = $_SESSION['translate']->it("Select");
                         $action .= " || <a href=\"{$action_link}\">{$action_label}</a>";
                         $editor = $cfg_editor;
                     }
                 } else {
                     $status = $_SESSION['translate']->it("not installed");
                     $action_link = $this->linkRef . "&amp;action=addEditor&amp;addEditor={$cfg_editor}&amp;fn={$file}";
                     $action_label = $_SESSION['translate']->it("Install");
                     $action = "<a href=\"{$action_link}\">{$action_label}</a>";
                     $action_link = $this->linkRef . "&amp;action=delFile&amp;delFile={$cfg_editor}&amp;filetyp=ext";
                     $action_label = $_SESSION['translate']->it("Remove");
                     $action .= " || <a href=\"{$action_link}\">{$action_label}</a>";
                     $editor = $cfg_editor;
                 }
                 $table[] = array($location, $editor, $status, $action);
             }
         } else {
             $this->content .= "<br />" . $_SESSION['translate']->it("No local editors found");
         }
         if (!$GLOBALS["core"]->isHub) {
             $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Status") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>");
             if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/")) {
                 PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/");
             }
             if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/editors/")) {
                 PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/editors/");
             }
             $dir = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('conf'));
             if (is_array($dir)) {
                 $location = $_SESSION['translate']->it("hub");
                 foreach ($dir as $file) {
                     include_once PHPWS_SOURCE_DIR . "files/xwysiwyg/editors/" . $file;
                     if (!in_array($cfg_editor, $editors)) {
                         $status = $_SESSION['translate']->it("not copied");
                         $action_link = $this->linkRef . "&amp;action=cpyEditor&amp;cpyEditor={$cfg_editor}";
                         $action_label = $_SESSION['translate']->it("Copy");
                         $action = "<a href=\"{$action_link}\">{$action_label}</a>";
                         $editor = $cfg_editor;
                     } else {
                         $status = $_SESSION['translate']->it("copied");
                         $action_link = $this->linkRef . "&amp;action=remEditor&amp;remEditor={$cfg_editor}";
                         $action_label = "";
                         $action = "na";
                         $editor = $cfg_editor;
                     }
                     $table[] = array($location, $editor, $status, $action);
                 }
             } else {
                 $this->content .= "<br />" . $_SESSION['translate']->it("No editors found on hub");
             }
         }
         $this->content .= PHPWS_Text::ezTable($table, 2, 2, 1, "", NULL, 1, "top");
         $this->content .= "<br /><br /><b>" . $_SESSION['translate']->it("Available editor-packages") . "</b>";
         $this->content .= "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"" . $this->linkRef . "&amp;action=manageEditor&amp;updList=1" . "\">" . $_SESSION['translate']->it("Update List") . "</a>";
         $table = array();
         $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Description") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>");
         $dir = PHPWS_File::readDirectory(PHPWS_HOME_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('tgz'));
         if (is_array($dir)) {
             $location = $_SESSION['translate']->it("local");
             foreach ($dir as $file) {
                 $status = $_SESSION['translate']->it("Archive package");
                 $action_link = $this->linkRef . "&amp;action=tarEditor&amp;tarEditor={$file}&amp;local=1";
                 $action_label = $_SESSION['translate']->it("Extract");
                 $action = "<a href=\"{$action_link}\">{$action_label}</a>";
                 $action_link = $this->linkRef . "&amp;action=delFile&amp;delFile={$file}&amp;filetyp=tgz";
                 $action_label = $_SESSION['translate']->it("Delete");
                 $action .= " || <a href=\"{$action_link}\">{$action_label}</a>";
                 $editor = $file;
                 $table[] = array($location, $editor, $status, $action);
             }
         }
         // fixme: remeber to update this entry !
         $file_loc = PHPWS_HOME_DIR . "files/xwysiwyg/editors/list.txt";
         $file_onl = "http://www.firebird.ch/xwysiwyg/editors/list41.txt";
         $location = $_SESSION['translate']->it("remote");
         if (!is_file($file_loc)) {
             PHPWS_File::fileCopy($file_onl, PHPWS_HOME_DIR . "files/xwysiwyg/editors/", "list.txt", TRUE, TRUE);
         }
         if ($rows = file($file_loc)) {
             PHPWS_Array::dropNulls($rows);
             foreach ($rows as $items) {
                 $item = explode("::", $items);
                 $editor = $item[0];
                 if (in_array($editor, $editors)) {
                     continue;
                 }
                 $status = $item[1];
                 $action_label = $_SESSION['translate']->it("Direct install ([var1]kb)", $item[3]);
                 $action_link = $this->linkRef . "&amp;action=tarEditor&amp;tarEditor=" . $item[2];
                 $action = "<a href=\"{$action_link}\">{$action_label}</a>";
                 $action_label = $_SESSION['translate']->it("Download");
                 $action_link = "http://www.firebird.ch/xwysiwyg/editors/" . $item[2];
                 $action .= " || <a href=\"{$action_link}\" target=\"_blank\">{$action_label}</a>";
                 $table[] = array($location, $editor, $status, $action);
             }
         }
         $this->content .= PHPWS_Text::ezTable($table, 2, 2, 1, "", NULL, 1, "top");
         $this->content .= $_SESSION['translate']->it("Depending on your server's security settings, direct install may not work.") . "<br />";
         $this->content .= $_SESSION['translate']->it("If everything fails, or if you want to modify the editor,") . "<br />";
         $this->content .= $_SESSION['translate']->it("download the file and copy it to /_phpws_/files/xwysiwyg/editors/ manually") . "<br />";
     } else {
         $this->content .= $_SESSION['translate']->it("Access was denied due to lack of proper permissions.");
     }
     // End of ADMINISTRATOR condition
 }
Пример #4
0
/**
 * @version $Id$
 * @author Adam Morton
 * @author Steven Levin
 */
function export($formId = NULL)
{
    if (!isset($formId)) {
        $message = dgettext('phatform', 'No form ID was passed');
        return new PHPWS_Error('phatform', 'export()', $message, 'continue', PHAT_DEBUG_MODE);
    }
    $exportDir = PHPWS_HOME_DIR . 'files/phatform/export/';
    $path = $exportDir;
    clearstatcache();
    if (!is_dir($path)) {
        if (is_writeable($exportDir)) {
            PHPWS_File::makeDir($path);
        } else {
            return PHPWS_Error::get(PHATFORM_EXPORT_PATH, 'phatform', 'Export.php::export()');
        }
    } elseif (!is_writeable($path)) {
        return PHPWS_Error::get(PHATFORM_EXPORT_PATH, 'phatform', 'Export.php::export()');
    }
    $sql = 'SELECT * FROM mod_phatform_form_' . $formId;
    $result = PHPWS_DB::getAll($sql);
    if (sizeof($result) > 0) {
        $data = '';
        foreach ($result[0] as $key => $value) {
            if ($key != 'position') {
                $data .= $key . "\t";
            }
        }
        foreach ($result as $entry) {
            $data .= "\n";
            foreach ($entry as $key => $value) {
                if ($key != 'position') {
                    if ($key == 'updated') {
                        $value = date(PHPWS_DATE_FORMAT . ' ' . PHPWS_TIME_FORMAT, $value);
                    } else {
                        $value = str_replace("\t", " ", $value);
                        $value = str_replace("\r\n", '', $value);
                        $value = str_replace("\n", '', $value);
                        $temp = $value;
                        if (is_array($temp)) {
                            $value = implode(',', $temp);
                        } else {
                            if (preg_match('/^[ao]:\\d+:/', $temp)) {
                                // unserialize data
                                $unsTemp = unserialize($temp);
                                if (is_array($unsTemp)) {
                                    $value = implode(',', $unsTemp);
                                } else {
                                    $value = $unsTemp;
                                }
                            }
                        }
                    }
                    $data .= "{$value}\t";
                }
            }
        }
    }
    $filename = 'form_' . $formId . '_export.' . time() . '.csv';
    $file = fopen($path . $filename, 'w');
    fwrite($file, $data);
    fclose($file);
    $goCode = 'zip -qmj ' . $path . $filename . '.zip ' . $path . $filename;
    system($goCode);
    $filename = $filename . '.zip';
    $filepath = 'files/phatform/export/' . $filename;
    header('Pragma: public');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filepath)) . ' GMT');
    header('Cache-Control: private', false);
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($filepath));
    header('Connection: close');
    readfile($filepath);
    exit;
}