示例#1
0
 public function __construct()
 {
     global $lC_Language, $lC_MessageStack;
     parent::__construct();
     $this->_page_contents = 'edit.php';
     if (isset($_POST['subaction']) && $_POST['subaction'] == 'confirm') {
         switch ($_GET['action']) {
             case 'save':
                 $data = array('image' => isset($_POST['categories_image']) ? $_POST['categories_image'] : null, 'parent_id' => $_POST['parent_id'], 'sort_order' => $_POST['sort_order'], 'mode' => $_POST['categories_mode'], 'link_target' => $_POST['categories_link_target'] == 'on' ? 1 : 0, 'custom_url' => $_POST['categories_custom_url'], 'status' => $_POST['categories_status'] == 'on' ? 1 : 0, 'nav' => $_POST['categories_visibility_nav'] == 'on' ? 1 : 0, 'box' => $_POST['categories_visibility_box'] == 'on' ? 1 : 0, 'name' => $_POST['categories_name'], 'menu_name' => $_POST['categories_menu_name'], 'blurb' => $_POST['categories_blurb'], 'description' => $_POST['categories_description'], 'permalink' => $_POST['categories_permalink'], 'tags' => $_POST['categories_tags']);
                 // access levels
                 if (isset($_POST['access_levels'])) {
                     $data['access_levels'] = $_POST['access_levels'];
                 }
                 if (isset($_POST['sync_all_products'])) {
                     $data['sync_all_products'] = $_POST['sync_all_products'];
                 }
                 if (isset($_POST['sync_all_children'])) {
                     $data['sync_all_children'] = $_POST['sync_all_children'];
                 }
                 /*
                  * Save the category information
                  *
                  * @param integer $_GET['cid'] The categories id used on update, null on insert
                  * @param array $data The categories information
                  * @access public
                  * @return boolean
                  */
                 $id = lC_Categories_Admin::save(isset($_GET['categories']) && is_numeric($_GET['categories']) ? $_GET['categories'] : null, $data);
                 if (is_numeric($id)) {
                     if (empty($_POST['save_close'])) {
                         lc_redirect_admin(lc_href_link_admin(FILENAME_DEFAULT, $this->_module . '=' . $id . '&cid=' . $_GET['cid'] . '&action=save'));
                     } else {
                         lc_redirect_admin(lc_href_link_admin(FILENAME_DEFAULT, $this->_module . '=' . $data['parent_id']));
                     }
                 } else {
                     $_SESSION['error'] = true;
                     $_SESSION['errmsg'] = $lC_Language->get('ms_error_action_not_performed');
                 }
                 break;
         }
     }
 }
 public static function importCategories($filename, $cwizard, $ctype, $cbackup, $cmapdata = NULL)
 {
     global $lC_Database, $lC_Datetime, $lC_Language, $lC_Image;
     if ($cwizard == 'false') {
         $cwizard = FALSE;
     } else {
         $cwizard = TRUE;
     }
     $lC_Categories = new lC_Categories_Admin();
     $error = FALSE;
     $errormsg = "";
     $msg = "";
     $uploaddir = DIR_FS_WORK . 'products_import_export/imports/';
     // $other .= 'Upload Dir: ' . $uploaddir;
     $uploadfile = $uploaddir . basename($filename);
     if (is_null($cmapdata)) {
         $columns = array('categories_id', 'image', 'parent_id', 'sort_order', 'mode', 'link_target', 'custom_url', 'status', 'nav', 'box', 'date_added', 'language_id', 'name', 'menu_name', 'blurb', 'description', 'keyword', 'tags');
     } else {
         // do the mapping of columns here with the mapdata
         $columns = array('categories_id', 'image', 'parent_id', 'sort_order', 'mode', 'link_target', 'custom_url', 'status', 'nav', 'box', 'date_added', 'language_id', 'name', 'menu_name', 'blurb', 'description', 'keyword', 'tags');
     }
     $ext = end(explode(".", $filename));
     if ($ext == 'txt') {
         $delim = "\t";
     } else {
         if ($ext == 'csv') {
             $delim = ",";
         } else {
             $delim = "\t";
         }
     }
     $row = 0;
     if (($handle = fopen($uploadfile, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, null, "\t")) !== FALSE) {
             $num = count($data);
             for ($c = 0; $c < $num; $c++) {
                 if ($row != 0) {
                     $import_array[$row][$columns[$c]] = $data[$c];
                 }
             }
             $row++;
         }
         fclose($handle);
     }
     $match_count = 0;
     $insert_count = 0;
     if ($cwizard) {
         // p wizard stuff like return columns and etc.
         $msg .= 'CWIZARD AGAIN!~!!!!!!!!!!';
     } else {
         // do the import as usual
         // utilize import array to go through each column and run on each to check for category id and if not matched import and remove from arrray
         foreach ($import_array as $category) {
             // Get the products ID for control
             $categories_id = $category['categories_id'];
             // check for a match in the database
             $Qcheck = $lC_Database->query("SELECT * FROM :table_categories WHERE categories_id = :categories_id");
             $Qcheck->bindTable(':table_categories', TABLE_CATEGORIES);
             $Qcheck->bindInt(':categories_id', $categories_id);
             $category_check = $Qcheck->numberOfRows();
             // build a cPath for later use
             $parents = self::getParentsPath($category['categories_id']);
             if (empty($parents)) {
                 $query = "cPath=" . $category['categories_id'];
             } else {
                 $query = "cPath=" . implode("_", array_reverse(explode("_", str_replace("_0", "", self::getParentsPath($category['categories_id']))))) . "_" . $category['categories_id'];
             }
             $query = str_replace("cPath=0_", "cPath=", $query);
             if ($category_check > 0) {
                 // the category exists in the database so were just going to update the category with the new data
                 $match_count++;
                 $cdaParts = explode("/", $category['date_added']);
                 $category_date_added = date("Y-m-d H:i:s", mktime(0, 0, 0, $cdaParts[0], $cdaParts[1], $cdaParts[2]));
                 // build data array of category information
                 $data['categories_id'] = $category['categories_id'];
                 $data['image'] = $category['image'];
                 $data['parent_id'] = $category['parent_id'];
                 $data['sort_order'] = $category['sort_order'];
                 $data['mode'] = $category['mode'];
                 $data['link_target'] = $category['link_target'];
                 $data['custom_url'] = $category['custom_url'];
                 $data['status'] = $category['status'];
                 $data['nav'] = $category['nav'];
                 $data['box'] = $category['box'];
                 $data['date_added'] = $category_date_added != '' ? $category_date_added : 'now()';
                 $data['last_modified'] = $category['last_modified'];
                 $data['name'][$category['language_id']] = $category['name'];
                 $data['menu_name'][$category['language_id']] = $category['menu_name'];
                 $data['permalink'][$category['language_id']] = '';
                 $data['blurb'][$category['language_id']] = $category['blurb'];
                 $data['description'][$category['language_id']] = $category['description'];
                 $data['keyword'][$category['language_id']] = $category['keyword'];
                 $data['tags'][$category['language_id']] = $category['tags'];
                 $lC_Categories->save($categories_id, $data);
             } else {
                 // the category doesnt exist so lets write it into the database
                 $insert_count++;
                 $cdaParts = explode("/", $category['date_added']);
                 $category_date_added = date("Y-m-d H:i:s", mktime(0, 0, 0, $cdaParts[0], $cdaParts[1], $cdaParts[2]));
                 // Insert using code from the catgories class
                 $error = false;
                 $lC_Database->startTransaction();
                 $Qcat = $lC_Database->query('insert into :table_categories (categories_id, categories_image, parent_id, sort_order, categories_mode, categories_link_target, categories_custom_url, categories_status, categories_visibility_nav, categories_visibility_box, date_added) values (:categories_id, :categories_image, :parent_id, :sort_order, :categories_mode, :categories_link_target, :categories_custom_url, :categories_status, :categories_visibility_nav, :categories_visibility_box, :date_added)');
                 $Qcat->bindInt(':categories_id', $category['categories_id']);
                 $Qcat->bindInt(':parent_id', $category['parent_id']);
                 $Qcat->bindTable(':table_categories', TABLE_CATEGORIES);
                 $Qcat->bindValue(':categories_image', $category['image']);
                 $Qcat->bindValue(':date_added', $category_date_added != '' ? $category_date_added : 'now()');
                 $Qcat->bindInt(':parent_id', $category['parent_id']);
                 $Qcat->bindInt(':sort_order', $category['sort_order']);
                 $Qcat->bindValue(':categories_mode', $category['mode']);
                 $Qcat->bindInt(':categories_link_target', $category['link_target']);
                 $Qcat->bindValue(':categories_custom_url', $category['custom_url']);
                 $Qcat->bindInt(':categories_status', $category['status']);
                 $Qcat->bindInt(':categories_visibility_nav', $category['nav']);
                 $Qcat->bindInt(':categories_visibility_box', $category['box']);
                 $Qcat->setLogging($_SESSION['module'], $id);
                 $Qcat->execute();
                 // remove this line from categories for it to be re inserted
                 $Qrcd = $lC_Database->query('delete from :table_categories_description where categories_id = :categories_id and language_id = :language_id');
                 $Qrcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
                 $Qrcd->bindInt(':categories_id', $categories_id);
                 $Qrcd->bindInt(':language_id', $category['language_id']);
                 $Qrcd->execute();
                 $Qcd = $lC_Database->query('insert into :table_categories_description (categories_id, language_id, categories_name, categories_menu_name, categories_blurb, categories_description, categories_tags) values (:categories_id, :language_id, :categories_name, :categories_menu_name, :categories_blurb, :categories_description, :categories_tags)');
                 $Qcd->bindTable(':table_categories_description', TABLE_CATEGORIES_DESCRIPTION);
                 $Qcd->bindInt(':categories_id', $categories_id);
                 $Qcd->bindInt(':language_id', $category['language_id']);
                 $Qcd->bindValue(':categories_name', $category['name']);
                 $Qcd->bindValue(':categories_menu_name', $category['menu_name']);
                 $Qcd->bindValue(':categories_blurb', $category['blurb']);
                 $Qcd->bindValue(':categories_description', $category['description']);
                 $Qcd->bindValue(':categories_tags', $category['tags']);
                 $Qcd->setLogging($_SESSION['module'], $categories_id);
                 $Qcd->execute();
                 if ($lC_Database->isError()) {
                     $error = true;
                     break;
                 }
                 // added for permalinks
                 if ($error === false) {
                     // get existing cat permalinks
                     $Qquery = $lC_Database->query("select permalink from :table_permalinks where type = :type and language_id = :language_id");
                     $Qquery->bindTable(':table_permalinks', TABLE_PERMALINKS);
                     $Qquery->bindInt(':type', 1);
                     $Qquery->bindInt(':language_id', $category['language_id']);
                     $Qquery->execute();
                     // make the array of existing permalinks
                     while ($Qquery->next()) {
                         $cat_pl_arr[] = $Qquery->value('permalink');
                     }
                     // what the new permalink is to be
                     $cat_permalink = lC_Products_import_export_Admin::generate_clean_permalink($category['name']);
                     // compare to existing cat permalinks and add random string to avoid duplicates if needed
                     if (in_array($cat_permalink, $cat_pl_arr)) {
                         $cat_permalink = $cat_permalink . '-' . self::randomString();
                     }
                     // insert the new permalink
                     $Qupdate = $lC_Database->query("insert into :table_permalinks (item_id, language_id, type, query, permalink) values (:item_id, :language_id, :type, :query, :permalink)");
                     $Qupdate->bindTable(':table_permalinks', TABLE_PERMALINKS);
                     $Qupdate->bindInt(':item_id', $categories_id);
                     $Qupdate->bindInt(':language_id', $category['language_id']);
                     $Qupdate->bindInt(':type', 1);
                     $Qupdate->bindValue(':query', $query);
                     $Qupdate->bindValue(':permalink', $cat_permalink);
                     $Qupdate->execute();
                     $Qquery->freeResult();
                     if ($lC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
                 if ($error === false) {
                     $lC_Database->commitTransaction();
                 } else {
                     $lC_Database->rollbackTransaction();
                 }
             }
         }
     }
     // end if $do
     // for all left in array match and update the records
     // use columns from import to figure out what columns are what
     if ($error || $errormsg != '') {
         if ($errormsg) {
             $icreturn['error'] = $errormsg . 'Error: ' . $error;
         }
     }
     if ($msg) {
         $icreturn['msg'] = $msg . ' cwizard: ' . $cwizard;
     }
     $icreturn['matched'] = $match_count;
     $icreturn['inserted'] = $insert_count;
     $icreturn['total'] = $match_count + $insert_count;
     return $icreturn;
 }