Esempio n. 1
0
 function step2()
 {
     require_once e_HANDLER . "db_verify_class.php";
     $dv = new db_verify();
     $frm = e107::getForm();
     $ns = e107::getRender();
     $mes = e107::getMessage();
     $newplug = $_GET['newplugin'];
     $this->pluginName = $newplug;
     //	$data = e107::getXml()->loadXMLfile(e_PLUGIN.'links_page/plugin.xml', 'advanced');
     //	print_a($data);
     //	echo "<pre>".var_export($data,true)."</pre>";
     $sqlFile = e_PLUGIN . $newplug . "/" . $newplug . "_sql.php";
     $ret = array();
     if (file_exists($sqlFile)) {
         $data = file_get_contents($sqlFile);
         $ret = $dv->getTables($data);
     }
     $text = $frm->open('newplugin-step3', 'post', e_SELF . '?mode=create&newplugin=' . $newplug . '&createFiles=' . $this->createFiles . '&step=3');
     $text .= "<ul class='nav nav-tabs'>\n";
     $text .= "<li class='active'><a data-toggle='tab' href='#xml'>" . EPL_ADLAN_109 . "</a></li>";
     $this->tableCount = count($ret['tables']);
     foreach ($ret['tables'] as $key => $table) {
         $text .= "<li><a data-toggle='tab'  href='#" . $table . "'>Table: " . $table . "</a></li>";
         $this->tableList[] = $table;
     }
     $text .= "<li><a data-toggle='tab'  href='#preferences'>" . LAN_PREFS . "</a></li>";
     $text .= "</ul>";
     $text .= "<div class='tab-content'>\n";
     $text .= "<div class='tab-pane active' id='xml'>\n";
     $text .= $this->pluginXml();
     $text .= "</div>";
     if (!empty($ret['tables'])) {
         foreach ($ret['tables'] as $key => $table) {
             $text .= "<div class='tab-pane' id='" . $table . "'>\n";
             $fields = $dv->getFields($ret['data'][$key]);
             $text .= $this->form($table, $fields);
             $text .= "</div>";
         }
     }
     $text .= "<div class='tab-pane' id='preferences'>\n";
     $text .= $this->prefs();
     $text .= "</div>";
     if (empty($ret['tables'])) {
         $text .= $frm->hidden($this->pluginName . '_ui[mode]', 'main');
         $text .= $frm->hidden($this->pluginName . '_ui[pluginName]', $this->pluginName);
     }
     $text .= "</div>";
     $text .= "\n\t\t\t<div class='buttons-bar center'>\n\t\t\t" . $frm->hidden('newplugin', $this->pluginName) . "\n\t\t\t" . $frm->admin_button('step', 3, 'other', LAN_GENERATE) . "\n\t\t\t</div>";
     $text .= $frm->close();
     $mes->addInfo(EPL_ADLAN_112);
     $mes->addInfo(EPL_ADLAN_113);
     $ns->tablerender(ADLAN_98 . SEP . EPL_ADLAN_114 . SEP . EPL_ADLAN_115, $mes->render() . $text);
 }
Esempio n. 2
0
 /**
  * Parse {plugin}_sql.php file and install/upgrade/uninstall tables.
  * @param $function string install|upgrade|uninstall
  * @param $plug - array of plugin data - mostly $plug['plugin_path']
  * @param array $options
  */
 function XmlTables($function, $plug, $options = array())
 {
     $sqlFile = e_PLUGIN . $plug['plugin_path'] . '/' . str_replace("_menu", "", $plug['plugin_path']) . "_sql.php";
     if (!file_exists($sqlFile)) {
         e107::getMessage()->addDebug("No SQL File Found at: " . $sqlFile);
         return;
     }
     if (!is_readable($sqlFile)) {
         e107::getMessage()->addError("Can't read SQL definition: " . $sqlFile);
         return;
     }
     require_once e_HANDLER . "db_verify_class.php";
     $dbv = new db_verify();
     $sql = e107::getDb();
     // Add or Remove Table --------------
     if ($function == 'install' || $function == 'uninstall') {
         $contents = file_get_contents($sqlFile);
         if (empty($contents)) {
             e107::getMessage()->addError("Can't read SQL definition: " . $sqlFile);
             return;
         }
         $tableData = $dbv->getTables($contents);
         foreach ($tableData['tables'] as $k => $v) {
             switch ($function) {
                 case "install":
                     $query = "CREATE TABLE  `" . MPREFIX . $v . "` (\n";
                     $query .= $tableData['data'][$k];
                     $query .= "\n) ENGINE=" . vartrue($tableData['engine'][$k], "InnoDB") . " DEFAULT CHARSET=utf8 ";
                     $txt = "Adding Table: <b>{$v}</b> ";
                     $status = $sql->db_Query($query) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
                     break;
                 case "uninstall":
                     if (!empty($options['delete_tables'])) {
                         $query = "DROP TABLE  `" . MPREFIX . $v . "`; ";
                         $txt = "Removing Table: {$v} <br />";
                         $status = $sql->db_Query_all($query) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
                     } else {
                         $status = E_MESSAGE_SUCCESS;
                         $txt = "Table {$v} left in place.";
                     }
                     break;
             }
             e107::getMessage()->add($txt, $status);
             e107::getMessage()->addDebug($query);
         }
     }
     // Upgrade Table --------------
     if ($function == 'upgrade') {
         $dbv->errors = array();
         $dbv->compare($plug['plugin_path']);
         if ($dbv->errors()) {
             $dbv->compileResults();
             $dbv->runFix();
         }
     }
 }