function get_data_from_xml_parser($xml_data = '')
 {
     $this->data['cip_ident'] = $this->getTagText($xml_data, 'cip', 0);
     $this->data['cip_version'] = $this->getTagAttr($xml_data, 'cip', 0, 'version');
     $active = false;
     if ($this->data['cip_ident'] == 'jos_commerce') {
         if ($this->isJoscom()) {
             $active = true;
         }
     } else {
         $query = 'select * from ' . TABLE_CIP . ' where cip_ident="' . $this->data['cip_ident'] . '"' . ($this->data['cip_version'] == NULL ? '' : ' and cip_version="' . $this->data['cip_version'] . '"') . ' and cip_installed=1';
         $result = cip_db_query($query, 'return');
         $active = vam_db_num_rows($result) > 0;
     }
     if ($active) {
         //if cip installed
         $obj = $xml_data->getElementsByTagName('active');
         if (is_object($obj)) {
             $mtag = $obj->item(0);
         }
     } else {
         $obj = $xml_data->getElementsByTagName('inactive');
         if (is_object($obj)) {
             $mtag = $obj->item(0);
         }
     }
     if (is_object($mtag)) {
         $this->getSubTags($mtag);
     }
 }
 function permissions_check_for_install()
 {
     foreach ($this->req as $id => $require) {
         if (strtolower($require) == 'jos_commerce') {
             if (!$this->isJoscom()) {
                 $this->error('This CIP is only for Jos-Commerce environment!');
                 return $this->error;
             }
             continue;
         }
         if (strtolower($require) == 'os_commerce') {
             if ($this->isJoscom()) {
                 $this->error('This CIP is only for OSCommerce environment!');
                 return $this->error;
             }
             continue;
         }
         $query = 'select * from ' . TABLE_CIP . ' where cip_ident="' . $require . '"' . ($this->ver[$id] != NULL ? ' and cip_version="' . $this->ver[$id] . '"' : '') . ' and cip_installed=1';
         $result = cip_db_query($query, 'return');
         if (vam_db_num_rows($result) == 0) {
             //required CIP not installed
             $this->error('CIP ' . $require . ' is not installed and is required !');
             return $this->error;
         }
     }
     return $this->error;
 }
 function do_remove()
 {
     if ($_REQUEST['remove_data'] == '1') {
         $sqlq = "DROP TABLE IF EXISTS `" . DB_PREFIX . $this->data['tablename'] . "`;";
         //$output .= "<div class=\"section\"><font class=\"section-title\">" . RUN_SQL_REMOVE_QUERY_TEXT . "</font><p class=\"sql_code\">" .
         //nl2br(htmlentities($sqlq)) . "</p></div>";
         if (cip_db_query($sqlq) === false) {
             $this->error('SQL error :<b>' . mysql_errno() . ' - ' . mysql_error() . '<br>' . $this->data['tablename']);
         }
     }
     $tblrows .= "  define('TABLE_" . strtoupper($this->data['tablename']) . "', (defined('DB_PREFIX') ? DB_PREFIX : '').'" . strtolower($this->data['tablename']) . "');\n";
     $add_str = $this->linebreak_fixing("\n" . $this->comment_string($tblrows));
     $output .= $this->remove_file_part("includes/database_tables.php", $add_str);
     if (!$this->isJoscom()) {
         $output .= $this->remove_file_part("admin/includes/database_tables.php", $add_str);
     }
     return $this->error;
 }
 function do_remove()
 {
     switch ($this->data['action']) {
         case 'addcol':
             $iscol = false;
             $query = "show fields from `" . DB_PREFIX . $this->data['tablename'] . "`";
             $rs = vam_db_query($query);
             while ($row = vam_db_fetch_array($rs)) {
                 if ($row['Field'] == $this->data['colname']) {
                     $iscol = true;
                     break;
                 }
             }
             if ($iscol) {
                 $sqlq = "alter table `" . DB_PREFIX . $this->data['tablename'] . "` drop `" . $this->data['colname'] . "`";
                 if (cip_db_query($sqlq) === false) {
                     $this->error('SQL error :<b>' . mysql_errno() . ' - ' . mysql_error() . '<br>' . $this->data['tablename']);
                     return $this->error;
                 }
             }
             break;
     }
     return $this->error;
 }
 function do_install($data = '')
 {
     if (!$data) {
         $data = $this->data['query'];
     }
     foreach ($data as $value) {
         $sql_array = parse_sql($value);
         foreach ($sql_array as $query) {
             if (cip_db_query($query) === false) {
                 $this->error('SQL error :<b>' . mysql_errno() . ' - ' . mysql_error() . '<br>' . $query);
                 return $this->error;
             }
         }
     }
     return $this->error;
 }
 function sql_backup()
 {
     vam_set_time_limit(0);
     $backup_file = DIR_FS_ADMIN_BACKUP . $this->cip_name . '.sql';
     // From original admin/backup.php:
     $fp = fopen($backup_file, 'w');
     $schema = '# Contrib Installer.' . "\n" . '# Makes customizing VaM Shop "simple".' . "\n" . '# Copyright (c) ' . date('Y') . ' Vlad Savitsky' . "\n" . '# http://vamshop.ru' . "\n" . '#' . "\n" . '# Database Backup For ' . STORE_NAME . "\n" . '#' . "\n" . '# Database: ' . DB_DATABASE . "\n" . '# Database Server: ' . DB_SERVER . "\n" . '#' . "\n" . '# Backup Date: ' . date(PHP_DATE_TIME_FORMAT) . "\n\n";
     fputs($fp, $schema);
     $tables_query = cip_db_query('show tables');
     while ($tables = vam_db_fetch_array($tables_query)) {
         list(, $table) = each($tables);
         $schema = 'drop table if exists `' . $table . '`;' . "\n" . 'create table `' . $table . '` (' . "\n";
         $table_list = array();
         $fields_query = cip_db_query("show fields from `" . $table . "`");
         while ($fields = vam_db_fetch_array($fields_query)) {
             $table_list[] = $fields['Field'];
             $schema .= '  `' . $fields['Field'] . '` ' . $fields['Type'];
             if (strlen($fields['Default']) > 0) {
                 $schema .= ' default \'' . $fields['Default'] . '\'';
             }
             if ($fields['Null'] != 'YES') {
                 $schema .= ' not null';
             }
             if (isset($fields['Extra'])) {
                 $schema .= ' ' . $fields['Extra'];
             }
             $schema .= ',' . "\n";
         }
         $schema = preg_replace("/,\n\$/", '', $schema);
         // add the keys
         $index = array();
         $keys_query = cip_db_query("show keys from `" . $table . "`");
         while ($keys = vam_db_fetch_array($keys_query)) {
             $kname = $keys['Key_name'];
             if (!isset($index[$kname])) {
                 $index[$kname] = array('unique' => !$keys['Non_unique'], 'columns' => array());
             }
             $index[$kname]['columns'][] = $keys['Column_name'];
             $index[$kname]['sub_part'][] = $keys['Sub_part'];
         }
         while (list($kname, $info) = each($index)) {
             $schema .= ',' . "\n";
             $columns = '';
             foreach ($info['columns'] as $id => $col) {
                 if ($columns == '') {
                     $columns .= "`" . $col . "`";
                 } else {
                     $columns .= ",`" . $col . "`";
                 }
                 if ($info['sub_part'][$id] != NULL && $info['sub_part'][$id] != 'NULL') {
                     $columns .= "(" . $info['sub_part'][$id] . ")";
                 }
             }
             if ($kname == 'PRIMARY') {
                 $schema .= '  PRIMARY KEY (' . $columns . ')';
             } elseif ($info['unique']) {
                 $schema .= '  UNIQUE `' . $kname . '` (' . $columns . ')';
             } else {
                 $schema .= '  KEY `' . $kname . '` (' . $columns . ')';
             }
         }
         $schema .= "\n" . ');' . "\n\n";
         fputs($fp, $schema);
         // dump the data
         $rows_query = cip_db_query("SELECT `" . implode('`, `', $table_list) . "` from `" . $table . "`");
         while ($rows = vam_db_fetch_array($rows_query)) {
             $schema = 'insert into `' . $table . '` (`' . implode('`, `', $table_list) . '`) values (';
             reset($table_list);
             while (list(, $i) = each($table_list)) {
                 if (!isset($rows[$i])) {
                     $schema .= 'NULL, ';
                 } elseif (vam_not_null($rows[$i])) {
                     $row = addslashes($rows[$i]);
                     $row = preg_replace("/\n#/", "\n" . '\\#', $row);
                     $schema .= '\'' . $row . '\', ';
                 } else {
                     $schema .= '\'\', ';
                 }
             }
             $schema = preg_replace('/, $/', '', $schema) . ');' . "\n";
             fputs($fp, $schema);
         }
     }
     fclose($fp);
     gzcompressfile($backup_file);
     if (is_file($backup_file)) {
         //chmod($backup_file, 0777);
         ci_remove($backup_file);
     }
     if (file_exists($backup_file . '.gz')) {
         chmod($backup_file . '.gz', 0777);
     }
 }
 function delete_database_table()
 {
     cip_db_query("DROP TABLE IF EXISTS `" . $this->table . "`");
 }