예제 #1
0
파일: Item.php 프로젝트: nsswaga/OSClass
 public function extendData($items)
 {
     if (defined('OC_ADMIN')) {
         $prefLocale = osc_current_admin_locale();
     } else {
         $prefLocale = osc_current_user_locale();
     }
     $results = array();
     foreach ($items as $item) {
         $descriptions = $this->conn->osc_dbFetchResults('SELECT * FROM %st_item_description WHERE fk_i_item_id = %d', DB_TABLE_PREFIX, $item['pk_i_id']);
         $item['locale'] = array();
         foreach ($descriptions as $desc) {
             if ($desc['s_title'] != "" || $desc['s_description'] != "") {
                 $item['locale'][$desc['fk_c_locale_code']] = $desc;
             }
         }
         if (isset($item['locale'][$prefLocale])) {
             $item['s_title'] = $item['locale'][$prefLocale]['s_title'];
             $item['s_description'] = $item['locale'][$prefLocale]['s_description'];
             $item['s_what'] = $item['locale'][$prefLocale]['s_what'];
         } else {
             $data = current($item['locale']);
             $item['s_title'] = $data['s_title'];
             $item['s_description'] = $data['s_description'];
             $item['s_what'] = $data['s_what'];
             unset($data);
         }
         $results[] = $item;
     }
     return $results;
 }
예제 #2
0
 public function processEditForm($new_item = array(), $files = array())
 {
     $param_name = 'new_item';
     Session::newInstance()->_setForm($param_name, $new_item);
     // keep values on session
     Session::newInstance()->_keepForm($param_name);
     $default_fields = array('gn_id' => NULL, 'gn_title' => '', 'gn_description' => '', 'gn_tags' => '', 'gn_lang' => osc_current_admin_locale());
     $new_item = array_merge($default_fields, $new_item);
     if (!$new_item['gn_title']) {
         throw new Exception(__('The title must not be empty', 'gz_news'));
     }
     if (!$new_item['gn_description']) {
         throw new Exception(__('The description must not be empty', 'gz_news'));
     }
     $dao = GzNewsDao::newInstance();
     if ($new_item['gn_id']) {
         $item_exists = $dao->findByPrimaryKey($new_item['gn_id']);
         if ($item_exists == FALSE) {
             throw new Exception(__('The new does not exists anymore', 'gz_news'));
         }
     }
     $success = $dao->save($new_item);
     if ($success) {
         if (!empty($files)) {
             $this->uploadFiles($success, $files);
         }
         Session::newInstance()->_dropKeepForm($param_name);
     }
     return $success;
 }
예제 #3
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
             }
             $this->_exportVariableToView("email", $this->emailManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("emails/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->emailManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->emailManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->emailManager->isIndelible($id)) {
                         $this->emailManager->updateInternalName($id, $s_internal_name);
                     }
                     osc_add_flash_ok_message(_m('The email/alert has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
                 }
                 osc_add_flash_error_message(_m('You can\'t repeat internal name'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('The email couldn\'t be updated, at least one title should not be empty'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=emails?action=edit&id=" . $id);
             break;
         default:
             $this->_exportVariableToView("prefLocale", osc_current_admin_locale());
             $this->_exportVariableToView("emails", $this->emailManager->listAll(1));
             $this->doView("emails/index.php");
     }
 }
예제 #4
0
 function __construct($install = false)
 {
     if (!$install) {
         // get user/admin locale
         if (OC_ADMIN) {
             $locale = osc_current_admin_locale();
         } else {
             $locale = osc_current_user_locale();
         }
         // load core
         $core_file = osc_translations_path() . $locale . '/core.mo';
         $this->_load($core_file, 'core');
         // load messages
         $messages_file = osc_themes_path() . osc_theme() . '/languages/' . $locale . '/messages.mo';
         if (!file_exists($messages_file)) {
             $messages_file = osc_translations_path() . $locale . '/messages.mo';
         }
         $this->_load($messages_file, 'messages');
         // load theme
         $domain = osc_theme();
         $theme_file = osc_themes_path() . $domain . '/languages/' . $locale . '/theme.mo';
         if (!file_exists($theme_file)) {
             if (!file_exists(osc_themes_path() . $domain)) {
                 $domain = 'modern';
             }
             $theme_file = osc_translations_path() . $locale . '/theme.mo';
         }
         $this->_load($theme_file, $domain);
         // load plugins
         $aPlugins = Plugins::listInstalled();
         foreach ($aPlugins as $plugin) {
             $domain = preg_replace('|/.*|', '', $plugin);
             $plugin_file = osc_plugins_path() . $domain . '/languages/' . $locale . '/messages.mo';
             if (file_exists($plugin_file)) {
                 $this->_load($plugin_file, $domain);
             }
         }
     } else {
         $core_file = osc_translations_path() . osc_current_admin_locale() . '/core.mo';
         $this->_load($core_file, 'core');
     }
 }
예제 #5
0
 /**
  *
  */
 function __construct($expired = false)
 {
     parent::__construct();
     $this->setTableName('t_item');
     $this->setFields(array('pk_i_id'));
     $this->withPattern = false;
     $this->withLocations = false;
     $this->withCategoryId = false;
     $this->withUserId = false;
     $this->withPicture = false;
     $this->withNoUserEmail = false;
     $this->price_min = null;
     $this->price_max = null;
     $this->user_ids = null;
     $this->itemId = null;
     $this->city_areas = array();
     $this->cities = array();
     $this->regions = array();
     $this->countries = array();
     $this->categories = array();
     $this->conditions = array();
     $this->tables = array();
     $this->tables_join = array();
     $this->search_fields = array();
     $this->itemConditions = array();
     $this->groupBy = '';
     $this->having = '';
     $this->order();
     $this->limit();
     $this->results_per_page = 10;
     if (!$expired) {
         // t_item
         $this->addItemConditions(sprintf("%st_item.b_enabled = 1 ", DB_TABLE_PREFIX));
         $this->addItemConditions(sprintf("%st_item.b_active = 1 ", DB_TABLE_PREFIX));
         $this->addItemConditions(sprintf("%st_item.b_spam = 0", DB_TABLE_PREFIX));
         $this->addItemConditions(sprintf("(%st_item.b_premium = 1 || %st_item.dt_expiration >= '%s')", DB_TABLE_PREFIX, DB_TABLE_PREFIX, date('Y-m-d H:i:s')));
     }
     $this->total_results = null;
     $this->total_results_table = null;
     // get all item_location data
     if (OC_ADMIN) {
         $this->addField(sprintf('%st_item_location.*', DB_TABLE_PREFIX));
         $this->locale_code = osc_current_admin_locale();
     } else {
         $this->locale_code = osc_current_user_locale();
     }
 }
예제 #6
0
        /**
         * Extends the given array $items with description in available locales
         *
         * @access public
         * @since unknown
         * @param type $items
         * @return array with description extended with all available locales
         */
        public function extendData($items)
        {
            if( OC_ADMIN ) {
                $prefLocale = osc_current_admin_locale();
            } else {
                $prefLocale = osc_current_user_locale();
            }

            $results = array();

            foreach ($items as $item) {
                $this->dao->select();
                $this->dao->from(DB_TABLE_PREFIX.'t_item_description');
                $this->dao->where(DB_TABLE_PREFIX.'t_item_description.fk_i_item_id', $item['pk_i_id']);

                $result = $this->dao->get();
                $descriptions = $result->result();

                $item['locale'] = array();
                foreach ($descriptions as $desc) {
                    if ($desc['s_title'] != "" || $desc['s_description'] != "") {
                        $item['locale'][$desc['fk_c_locale_code']] = $desc;
                    }
                }
                if (isset($item['locale'][$prefLocale])) {
                    $item['s_title'] = $item['locale'][$prefLocale]['s_title'];
                    $item['s_description'] = $item['locale'][$prefLocale]['s_description'];
                } else {
                    $data = current($item['locale']);
                    $item['s_title'] = $data['s_title'];
                    $item['s_description'] = $data['s_description'];
                    unset($data);
                }

                // populate locations and category_name
                $this->dao->select(DB_TABLE_PREFIX.'t_item_location.*, cd.s_name as s_category_name');
                // select sum item_stats
                $this->dao->select('SUM(`s`.`i_num_views`) as `i_num_views`' );
                $this->dao->select('SUM(`s`.`i_num_spam`) as `i_num_spam`' );
                $this->dao->select('SUM(`s`.`i_num_bad_classified`) as `i_num_bad_classified`' );
                $this->dao->select('SUM(`s`.`i_num_repeated`) as `i_num_repeated`' );
                $this->dao->select('SUM(`s`.`i_num_offensive`) as `i_num_offensive`' );
                $this->dao->select('SUM(`s`.`i_num_expired`) as `i_num_expired` ' );
                $this->dao->select('SUM(`s`.`i_num_premium_views`) as `i_num_premium_views` ' );

                $this->dao->from(DB_TABLE_PREFIX.'t_item_location');
                $this->dao->from(DB_TABLE_PREFIX.'t_category_description as cd');
                $this->dao->from(DB_TABLE_PREFIX.'t_item_stats as s');
                $this->dao->where(DB_TABLE_PREFIX.'t_item_location.fk_i_item_id', $item['pk_i_id']);
//                $this->dao->where(DB_TABLE_PREFIX.'t_item_stats.fk_i_item_id', $item['pk_i_id']);
                $this->dao->where('s.fk_i_item_id', $item['pk_i_id']);
                $this->dao->where('cd.fk_i_category_id', $item['fk_i_category_id']);
                // group by item_id
                $this->dao->groupBy('fk_i_item_id');

                $result = $this->dao->get();
                $extraFields = $result->row();

                foreach($extraFields as $key => $value) {
                    $item[$key] = $value;
                }

                $results[] = $item;
            }
            return $results;
        }
예제 #7
0
function oc_install_example_data()
{
    require_once LIB_PATH . 'osclass/formatting.php';
    require LIB_PATH . 'osclass/installer/categories.php';
    require_once LIB_PATH . 'osclass/model/Category.php';
    $mCat = Category::newInstance();
    if (!function_exists('osc_apply_filter')) {
        function osc_apply_filter($dummyfilter, $str)
        {
            return $str;
        }
    }
    foreach ($categories as $category) {
        $fields['pk_i_id'] = $category['pk_i_id'];
        $fields['fk_i_parent_id'] = $category['fk_i_parent_id'];
        $fields['i_position'] = $category['i_position'];
        $fields['i_expiration_days'] = 0;
        $fields['b_enabled'] = 0;
        $aFieldsDescription[osc_current_admin_locale()]['s_name'] = $category['s_name'];
        $mCat->insert($fields, $aFieldsDescription);
    }
}
예제 #8
0
" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <script type="text/javascript">
        var osc = window.osc || {};
<?php 
/* TODO: enqueue js lang strings */
$lang = array('no_subcategory' => __('No Subcategory'), 'select_subcategory' => __('Select Subcategory'));
$locales = osc_get_locales();
$codes = array();
foreach ($locales as $locale) {
    $codes[] = '\'' . osc_esc_js($locale['pk_c_code']) . '\'';
}
?>
        osc.locales = {};
        osc.locales.current = '<?php 
echo osc_current_admin_locale();
?>
';
        osc.locales.codes   = new Array(<?php 
echo join(',', $codes);
?>
);
        osc.locales.string  = '[name*="' + osc.locales.codes.join('"],[name*="') + '"],.' + osc.locales.codes.join(',.');
        osc.langs = <?php 
echo json_encode($lang);
?>
;
    </script>
    <?php 
osc_run_hook('admin_header');
?>
예제 #9
0
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             }
             $this->_exportVariableToView("page", $this->pageManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("pages/frm.php");
             break;
         case 'edit_post':
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             // sanitize internal name
             $s_internal_name = osc_sanitizeString($s_internal_name);
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages?action=edit&id=" . $id);
             }
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->pageManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->pageManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->pageManager->isIndelible($id)) {
                         $this->pageManager->updateInternalName($id, $s_internal_name);
                     }
                     osc_add_flash_ok_message(_m('The page has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
                 }
                 osc_add_flash_error_message(_m("You can't repeat internal name"), 'admin');
             } else {
                 osc_add_flash_error_message(_m("The page couldn't be updated, at least one title should not be empty"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages?action=edit&id=" . $id);
             break;
         case 'add':
             $this->_exportVariableToView("page", array());
             $this->doView("pages/frm.php");
             break;
         case 'add_post':
             // setForm just in case the form fails
             foreach (Params::getParamsAsArray('', false) as $k => $v) {
                 Session::newInstance()->_setForm($k, $v);
             }
             $s_internal_name = Params::getParam("s_internal_name");
             // sanitize internal name
             $s_internal_name = osc_sanitizeString($s_internal_name);
             if ($s_internal_name == '') {
                 osc_add_flash_error_message(_m('You have to set an internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             if (!WebThemes::newInstance()->isValidPage($s_internal_name)) {
                 osc_add_flash_error_message(_m('You have to set a different internal name'), 'admin');
                 $this->redirectTo(osc_admin_base_url(true) . "?page=pages&action=add");
             }
             $page = $this->pageManager->findByInternalName($s_internal_name);
             if (!isset($page['pk_i_id'])) {
                 $aFields = array('s_internal_name' => $s_internal_name, 'b_indelible' => '0');
                 $aFieldsDescription = array();
                 $postParams = Params::getParamsAsArray('', false);
                 $not_empty = false;
                 foreach ($postParams as $k => $v) {
                     if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                         if ($m[2] == 's_title' && $v != '') {
                             $not_empty = true;
                         }
                         $aFieldsDescription[$m[1]][$m[2]] = $v;
                     }
                 }
                 if ($not_empty) {
                     $result = $this->pageManager->insert($aFields, $aFieldsDescription);
                     osc_add_flash_ok_message(_m('The page has been added'), 'admin');
                 } else {
                     osc_add_flash_error_message(_m("The page couldn't be added, at least one title should not be empty"), 'admin');
                 }
             } else {
                 osc_add_flash_error_message(_m("Oops! That internal name is already in use. We can't made the changes"), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         case 'delete':
             $id = Params::getParam("id");
             $page_deleted_correcty = 0;
             $page_deleted_error = 0;
             $page_indelible = 0;
             if (!is_array($id)) {
                 $id = array($id);
             }
             foreach ($id as $_id) {
                 $result = (int) $this->pageManager->deleteByPrimaryKey($_id);
                 switch ($result) {
                     case -1:
                         $page_indelible++;
                         break;
                     case 0:
                         $page_deleted_error++;
                         break;
                     case 1:
                         $page_deleted_correcty++;
                 }
             }
             if ($page_indelible > 0) {
                 if ($page_indelible == 1) {
                     osc_add_flash_error_message(_m("One page can't be deleted because it is indelible"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted because are indelible"), $page_indelible), 'admin');
                 }
             }
             if ($page_deleted_error > 0) {
                 if ($page_deleted_error == 1) {
                     osc_add_flash_error_message(_m("One page couldn't be deleted"), 'admin');
                 } else {
                     osc_add_flash_error_message(sprintf(_m("%s pages couldn't be deleted"), $page_deleted_error), 'admin');
                 }
             }
             if ($page_deleted_correcty > 0) {
                 if ($page_deleted_correcty == 1) {
                     osc_add_flash_ok_message(_m('One page has been deleted correctly'), 'admin');
                 } else {
                     osc_add_flash_ok_message(sprintf(_m('%s pages have been deleted correctly'), $page_deleted_correcty), 'admin');
                 }
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=pages");
             break;
         default:
             $this->_exportVariableToView("prefLocale", osc_current_admin_locale());
             $this->_exportVariableToView("pages", $this->pageManager->listAll(0));
             $this->doView("pages/index.php");
     }
 }
예제 #10
0
파일: emails.php 프로젝트: naneri/Osclass
 function doModel()
 {
     parent::doModel();
     //specific things for this class
     switch ($this->action) {
         case 'edit':
             if (Params::getParam("id") == '') {
                 $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
             }
             $form = count(Session::newInstance()->_getForm());
             $keepForm = count(Session::newInstance()->_getKeepForm());
             if ($form == 0 || $form == $keepForm) {
                 Session::newInstance()->_dropKeepForm();
             }
             $this->_exportVariableToView("email", $this->emailManager->findByPrimaryKey(Params::getParam("id")));
             $this->doView("emails/frm.php");
             break;
         case 'edit_post':
             osc_csrf_check();
             $id = Params::getParam("id");
             $s_internal_name = Params::getParam("s_internal_name");
             $aFieldsDescription = array();
             $postParams = Params::getParamsAsArray('', false);
             $not_empty = false;
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_title' && $v != '') {
                         $not_empty = true;
                     }
                     $aFieldsDescription[$m[1]][$m[2]] = $v;
                 }
             }
             Session::newInstance()->_setForm('s_internal_name', $s_internal_name);
             Session::newInstance()->_setForm('aFieldsDescription', $aFieldsDescription);
             if ($not_empty) {
                 foreach ($aFieldsDescription as $k => $_data) {
                     $this->emailManager->updateDescription($id, $k, $_data['s_title'], $_data['s_text']);
                 }
                 if (!$this->emailManager->internalNameExists($id, $s_internal_name)) {
                     if (!$this->emailManager->isIndelible($id)) {
                         $this->emailManager->updateInternalName($id, $s_internal_name);
                     }
                     Session::newInstance()->_clearVariables();
                     osc_add_flash_ok_message(_m('The email/alert has been updated'), 'admin');
                     $this->redirectTo(osc_admin_base_url(true) . "?page=emails");
                 }
                 osc_add_flash_error_message(_m('You can\'t repeat internal name'), 'admin');
             } else {
                 osc_add_flash_error_message(_m('The email couldn\'t be updated, at least one title should not be empty'), 'admin');
             }
             $this->redirectTo(osc_admin_base_url(true) . "?page=emails&action=edit&id=" . $id);
             break;
         default:
             //-
             if (Params::getParam('iDisplayLength') == '') {
                 Params::setParam('iDisplayLength', 10);
             }
             $p_iPage = 1;
             if (is_numeric(Params::getParam('iPage')) && Params::getParam('iPage') >= 1) {
                 $p_iPage = Params::getParam('iPage');
             }
             Params::setParam('iPage', $p_iPage);
             $prefLocale = osc_current_admin_locale();
             $emails = $this->emailManager->listAll(1);
             // pagination
             $start = ($p_iPage - 1) * Params::getParam('iDisplayLength');
             $limit = Params::getParam('iDisplayLength');
             $count = count($emails);
             $displayRecords = $limit;
             if ($start + $limit > $count) {
                 $displayRecords = $start + $limit - $count;
             }
             // ----
             $aData = array();
             $max = $start + $limit;
             if ($max > $count) {
                 $max = $count;
             }
             for ($i = $start; $i < $max; $i++) {
                 $email = $emails[$i];
                 if (isset($email['locale'][$prefLocale]) && !empty($email['locale'][$prefLocale]['s_title'])) {
                     $title = $email['locale'][$prefLocale];
                 } else {
                     $title = current($email['locale']);
                 }
                 $options = array();
                 $options[] = '<a href="' . osc_admin_base_url(true) . '?page=emails&amp;action=edit&amp;id=' . $email["pk_i_id"] . '">' . __('Edit') . '</a>';
                 $auxOptions = '<ul>' . PHP_EOL;
                 foreach ($options as $actual) {
                     $auxOptions .= '<li>' . $actual . '</li>' . PHP_EOL;
                 }
                 $actions = '<div class="actions">' . $auxOptions . '</div>' . PHP_EOL;
                 $row = array();
                 $row[] = $email['s_internal_name'] . $actions;
                 $row[] = $title['s_title'];
                 $aData[] = $row;
             }
             // ----
             $array['iTotalRecords'] = $displayRecords;
             $array['iTotalDisplayRecords'] = count($emails);
             $array['iDisplayLength'] = $limit;
             $array['aaData'] = $aData;
             $page = (int) Params::getParam('iPage');
             if (count($array['aaData']) == 0 && $page != 1) {
                 $total = (int) $array['iTotalDisplayRecords'];
                 $maxPage = ceil($total / (int) $array['iDisplayLength']);
                 $url = osc_admin_base_url(true) . '?' . $_SERVER['QUERY_STRING'];
                 if ($maxPage == 0) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=1', $url);
                     $this->redirectTo($url);
                 }
                 if ($page > 1) {
                     $url = preg_replace('/&iPage=(\\d)+/', '&iPage=' . $maxPage, $url);
                     $this->redirectTo($url);
                 }
             }
             $this->_exportVariableToView('aEmails', $array);
             $this->doView("emails/index.php");
     }
 }
예제 #11
0
function oc_install_example_data()
{
    require_once LIB_PATH . 'osclass/formatting.php';
    require LIB_PATH . 'osclass/installer/basic_data.php';
    require_once LIB_PATH . 'osclass/model/Category.php';
    $mCat = Category::newInstance();
    if (!function_exists('osc_apply_filter')) {
        function osc_apply_filter($dummyfilter, $str)
        {
            return $str;
        }
    }
    foreach ($categories as $category) {
        $fields['pk_i_id'] = $category['pk_i_id'];
        $fields['fk_i_parent_id'] = $category['fk_i_parent_id'];
        $fields['i_position'] = $category['i_position'];
        $fields['i_expiration_days'] = 0;
        $fields['b_enabled'] = 1;
        $aFieldsDescription[osc_current_admin_locale()]['s_name'] = $category['s_name'];
        $mCat->insert($fields, $aFieldsDescription);
    }
    require_once LIB_PATH . 'osclass/model/Item.php';
    require_once LIB_PATH . 'osclass/model/ItemComment.php';
    require_once LIB_PATH . 'osclass/model/ItemLocation.php';
    require_once LIB_PATH . 'osclass/model/ItemResource.php';
    require_once LIB_PATH . 'osclass/model/ItemStats.php';
    require_once LIB_PATH . 'osclass/model/User.php';
    require_once LIB_PATH . 'osclass/model/Country.php';
    require_once LIB_PATH . 'osclass/model/Region.php';
    require_once LIB_PATH . 'osclass/model/City.php';
    require_once LIB_PATH . 'osclass/model/CityArea.php';
    require_once LIB_PATH . 'osclass/model/Field.php';
    require_once LIB_PATH . 'osclass/model/Page.php';
    require_once LIB_PATH . 'osclass/model/Log.php';
    require_once LIB_PATH . 'osclass/model/CategoryStats.php';
    require_once LIB_PATH . 'osclass/model/CountryStats.php';
    require_once LIB_PATH . 'osclass/model/RegionStats.php';
    require_once LIB_PATH . 'osclass/model/CityStats.php';
    require_once LIB_PATH . 'osclass/helpers/hSecurity.php';
    require_once LIB_PATH . 'osclass/helpers/hValidate.php';
    require_once LIB_PATH . 'osclass/helpers/hUsers.php';
    require_once LIB_PATH . 'osclass/ItemActions.php';
    $mItem = new ItemActions(true);
    foreach ($item as $k => $v) {
        if ($k == 'description' || $k == 'title') {
            Params::setParam($k, array(osc_current_admin_locale() => $v));
        } else {
            Params::setParam($k, $v);
        }
    }
    $mItem->prepareData(true);
    $successItem = $mItem->add();
    $successPageresult = Page::newInstance()->insert(array('s_internal_name' => $page['s_internal_name'], 'b_indelible' => 0, 's_meta' => json_encode('')), array(osc_current_admin_locale() => array('s_title' => $page['s_title'], 's_text' => $page['s_text'])));
}
예제 #12
0
 /**
  * Make the SQL for the search with all the conditions and filters specified
  *
  * @access private
  * @since unknown
  * @param bool $count
  */
 private function _makeSQL($count = false, $premium = false)
 {
     $arrayConditions = $this->_conditions();
     $extraFields = $arrayConditions['extraFields'];
     $conditionsSQL = $arrayConditions['conditionsSQL'];
     $sql = '';
     if ($this->withItemId) {
         // add field s_user_name
         $this->dao->select(sprintf('%st_item.*, %st_item.s_contact_name as s_user_name', DB_TABLE_PREFIX, DB_TABLE_PREFIX));
         $this->dao->from(sprintf('%st_item', DB_TABLE_PREFIX));
         $this->dao->where('pk_i_id', (int) $this->itemId);
     } else {
         if ($count) {
             $this->dao->select(DB_TABLE_PREFIX . 't_item.pk_i_id');
             $this->dao->select($extraFields);
             // plugins!
         } else {
             $this->dao->select(DB_TABLE_PREFIX . 't_item.*, ' . DB_TABLE_PREFIX . 't_item.s_contact_name as s_user_name');
             $this->dao->select($extraFields);
             // plugins!
         }
         $this->dao->from(DB_TABLE_PREFIX . 't_item');
         if ($this->withNoUserEmail) {
             $this->dao->where(DB_TABLE_PREFIX . 't_item.s_contact_email', $this->sEmail);
         }
         if ($this->withPattern) {
             $this->dao->join(DB_TABLE_PREFIX . 't_item_description as d', 'd.fk_i_item_id = ' . DB_TABLE_PREFIX . 't_item.pk_i_id', 'LEFT');
             $this->dao->where(sprintf("MATCH(d.s_title, d.s_description) AGAINST('%s' IN BOOLEAN MODE)", $this->sPattern));
             if (empty($this->locale_code)) {
                 if (OC_ADMIN) {
                     $this->locale_code[osc_current_admin_locale()] = osc_current_admin_locale();
                 } else {
                     $this->locale_code[osc_current_user_locale()] = osc_current_user_locale();
                 }
             }
             $this->dao->where(sprintf("( d.fk_c_locale_code LIKE '%s' )", implode("' d.fk_c_locale_code LIKE '", $this->locale_code)));
         }
         // item conditions
         if (count($this->itemConditions) > 0) {
             $itemConditions = implode(' AND ', osc_apply_filter('sql_search_item_conditions', $this->itemConditions));
             $this->dao->where($itemConditions);
         }
         if ($this->withCategoryId && count($this->categories) > 0) {
             $this->dao->where(sprintf("%st_item.fk_i_category_id", DB_TABLE_PREFIX) . ' IN (' . implode(', ', $this->categories) . ')');
         }
         if ($this->withUserId) {
             $this->_fromUser();
         }
         if ($this->withLocations || OC_ADMIN) {
             $this->dao->join(sprintf('%st_item_location', DB_TABLE_PREFIX), sprintf('%st_item_location.fk_i_item_id = %st_item.pk_i_id', DB_TABLE_PREFIX, DB_TABLE_PREFIX), 'LEFT');
             $this->_addLocations();
         }
         if ($this->withPicture) {
             $this->dao->join(sprintf('%st_item_resource', DB_TABLE_PREFIX), sprintf('%st_item_resource.fk_i_item_id = %st_item.pk_i_id', DB_TABLE_PREFIX, DB_TABLE_PREFIX), 'LEFT');
             $this->dao->where(sprintf("%st_item_resource.s_content_type LIKE '%%image%%' ", DB_TABLE_PREFIX, DB_TABLE_PREFIX, DB_TABLE_PREFIX));
             $this->dao->groupBy(DB_TABLE_PREFIX . 't_item.pk_i_id');
         }
         if ($this->onlyPremium) {
             $this->dao->where(sprintf("%st_item.b_premium = 1", DB_TABLE_PREFIX));
         }
         $this->_priceRange();
         // add joinTables
         $this->_joinTable();
         // PLUGINS TABLES !!
         if (!empty($this->tables)) {
             $tables = implode(', ', $this->tables);
             $this->dao->from($tables);
         }
         // WHERE PLUGINS extra conditions
         if (count($this->conditions) > 0) {
             $this->dao->where($conditionsSQL);
         }
         // ---------------------------------------------------------
         // groupBy
         if ($this->groupBy != '') {
             $this->dao->groupBy($this->groupBy);
         }
         // having
         if ($this->having != '') {
             $this->dao->having($this->having);
         }
         // ---------------------------------------------------------
         // order & limit
         $this->dao->orderBy($this->order_column, $this->order_direction);
         if ($count) {
             $this->dao->limit(100 * $this->results_per_page);
         } else {
             $this->dao->limit($this->limit_init, $this->results_per_page);
         }
     }
     $this->sql = $this->dao->_getSelect();
     // reset dao attributes
     $this->dao->_resetSelect();
     return $this->sql;
 }
예제 #13
0
파일: Item.php 프로젝트: randomecho/OSClass
 /**
  * Extends the given array $items with description in available locales
  *
  * @access public
  * @since unknown
  * @param type $items
  * @return array with description extended with all available locales 
  */
 public function extendData($items)
 {
     if (OC_ADMIN) {
         $prefLocale = osc_current_admin_locale();
     } else {
         $prefLocale = osc_current_user_locale();
     }
     $results = array();
     foreach ($items as $item) {
         $this->dao->select();
         $this->dao->from(DB_TABLE_PREFIX . 't_item_description');
         $this->dao->where(DB_TABLE_PREFIX . 't_item_description.fk_i_item_id', $item['pk_i_id']);
         $result = $this->dao->get();
         $descriptions = $result->result();
         $item['locale'] = array();
         foreach ($descriptions as $desc) {
             if ($desc['s_title'] != "" || $desc['s_description'] != "") {
                 $item['locale'][$desc['fk_c_locale_code']] = $desc;
             }
         }
         if (isset($item['locale'][$prefLocale])) {
             $item['s_title'] = $item['locale'][$prefLocale]['s_title'];
             $item['s_description'] = $item['locale'][$prefLocale]['s_description'];
         } else {
             $data = current($item['locale']);
             $item['s_title'] = $data['s_title'];
             $item['s_description'] = $data['s_description'];
             unset($data);
         }
         // populate locations and category_name
         $this->dao->select(DB_TABLE_PREFIX . 't_item_location.*, ' . DB_TABLE_PREFIX . 't_item_stats.*, cd.s_name as s_category_name');
         $this->dao->from(DB_TABLE_PREFIX . 't_item_location');
         $this->dao->from(DB_TABLE_PREFIX . 't_category_description as cd');
         $this->dao->from(DB_TABLE_PREFIX . 't_item_stats');
         $this->dao->where(DB_TABLE_PREFIX . 't_item_location.fk_i_item_id', $item['pk_i_id']);
         $this->dao->where(DB_TABLE_PREFIX . 't_item_stats.fk_i_item_id', $item['pk_i_id']);
         $this->dao->where('cd.fk_i_category_id', $item['fk_i_category_id']);
         $result = $this->dao->get();
         $extraFields = $result->row();
         foreach ($extraFields as $key => $value) {
             $item[$key] = $value;
         }
         $results[] = $item;
     }
     return $results;
 }
예제 #14
0
파일: Item.php 프로젝트: acharei/OSClass
 /**
  * Extends the given array $items with description in available locales
  *
  * @access public
  * @since unknown
  * @param type $items
  * @return array with description extended with all available locales 
  */
 public function extendData($items)
 {
     if (defined('OC_ADMIN')) {
         $prefLocale = osc_current_admin_locale();
     } else {
         $prefLocale = osc_current_user_locale();
     }
     $results = array();
     foreach ($items as $item) {
         $this->dao->select();
         $this->dao->from(DB_TABLE_PREFIX . 't_item_description');
         $this->dao->where('fk_i_item_id', $item['pk_i_id']);
         $result = $this->dao->get();
         $descriptions = $result->result();
         $item['locale'] = array();
         foreach ($descriptions as $desc) {
             if ($desc['s_title'] != "" || $desc['s_description'] != "") {
                 $item['locale'][$desc['fk_c_locale_code']] = $desc;
             }
         }
         if (isset($item['locale'][$prefLocale])) {
             $item['s_title'] = $item['locale'][$prefLocale]['s_title'];
             $item['s_description'] = $item['locale'][$prefLocale]['s_description'];
             $item['s_what'] = $item['locale'][$prefLocale]['s_what'];
         } else {
             $data = current($item['locale']);
             $item['s_title'] = $data['s_title'];
             $item['s_description'] = $data['s_description'];
             $item['s_what'] = $data['s_what'];
             unset($data);
         }
         $results[] = $item;
     }
     return $results;
 }
예제 #15
0
파일: ajax.php 프로젝트: nsswaga/OSClass
 function doModel()
 {
     //specific things for this class
     switch ($this->action) {
         case 'bulk_actions':
             break;
         case 'regions':
             //Return regions given a countryId
             $regions = Region::newInstance()->getByCountry(Params::getParam("countryId"));
             echo json_encode($regions);
             break;
         case 'cities':
             //Returns cities given a regionId
             $cities = City::newInstance()->getByRegion(Params::getParam("regionId"));
             echo json_encode($cities);
             break;
         case 'location':
             // This is the autocomplete AJAX
             $cities = City::newInstance()->ajax(Params::getParam("term"));
             echo json_encode($cities);
             break;
         case 'alerts':
             // Allow to register to an alert given (not sure it's used on admin)
             $alert = Params::getParam("alert");
             $email = Params::getParam("email");
             $userid = Params::getParam("userid");
             if ($alert != '' && $email != '') {
                 Alerts::newInstance()->insert(array('fk_i_user_id' => $userid, 's_email' => $email, 's_search' => $alert, 'e_type' => 'DAILY'));
                 echo "1";
                 return true;
             }
             echo '0';
             break;
         case 'runhook':
             //Run hooks
             $hook = Params::getParam("hook");
             switch ($hook) {
                 case 'item_form':
                     $catId = Params::getParam("catId");
                     if ($catId != '') {
                         osc_run_hook("item_form", $catId);
                     } else {
                         osc_run_hook("item_form");
                     }
                     break;
                 case 'item_edit':
                     $catId = Params::getParam("catId");
                     $itemId = Params::getParam("itemId");
                     osc_run_hook("item_edit", $catId, $itemId);
                     break;
                 default:
                     if ($hook == '') {
                         return false;
                     } else {
                         osc_run_hook($hook);
                     }
                     break;
             }
             break;
         case 'items':
             // Return items (use external file oc-admin/ajax/item_processing.php)
             require_once osc_admin_base_path() . 'ajax/items_processing.php';
             $items_processing = new items_processing_ajax(Params::getParamsAsArray("get"));
             break;
         case 'media':
             // Return items (use external file oc-admin/ajax/media_processing.php)
             require_once osc_admin_base_path() . 'ajax/media_processing.php';
             $media_processing = new media_processing_ajax(Params::getParamsAsArray("get"));
             break;
         case 'categories_order':
             // Save the order of the categories
             $aIds = Params::getParam('list');
             $orderParent = 0;
             $orderSub = 0;
             $catParent = 0;
             $catManager = Category::newInstance();
             foreach ($aIds as $id => $parent) {
                 if ($parent == 'root') {
                     if (!$catManager->update_order($id, $orderParent)) {
                         $error = 1;
                     }
                     // set parent category
                     $conditions = array('pk_i_id' => $id);
                     $array['fk_i_parent_id'] = DB_CONST_NULL;
                     if (!$catManager->update($array, $conditions) > 0) {
                         $error = 1;
                     }
                     $orderParent++;
                 } else {
                     if ($parent != $catParent) {
                         $catParent = $parent;
                         $orderSub = 0;
                     }
                     if (!$catManager->update_order($id, $orderSub)) {
                         $error = 1;
                     }
                     // set parent category
                     $conditions = array('pk_i_id' => $id);
                     $array['fk_i_parent_id'] = $catParent;
                     if (!$catManager->update($array, $conditions) > 0) {
                         $error = 1;
                     }
                     $orderSub++;
                 }
             }
             $result = "{";
             $error = 0;
             if ($error) {
                 $result .= '"error" : "' . __("Some error ocurred") . '"';
             } else {
                 $result .= '"ok" : "' . __("Order saved") . '"';
             }
             $result .= "}";
             echo $result;
             break;
         case 'category_edit_iframe':
             $this->_exportVariableToView("category", Category::newInstance()->findByPrimaryKey(Params::getParam("id")));
             $this->_exportVariableToView("languages", OSCLocale::newInstance()->listAllEnabled());
             $this->doView("categories/iframe.php");
             break;
         case 'field_categories_iframe':
             $selected = Field::newInstance()->categories(Params::getParam("id"));
             if ($selected == null) {
                 $selected = array();
             }
             $this->_exportVariableToView("selected", $selected);
             $this->_exportVariableToView("field", Field::newInstance()->findByPrimaryKey(Params::getParam("id")));
             $this->_exportVariableToView("categories", Category::newInstance()->toTreeAll());
             $this->doView("fields/iframe.php");
             break;
         case 'field_categories_post':
             $error = 0;
             if (!$error) {
                 try {
                     $field = Field::newInstance()->findByName(Params::getParam("s_name"));
                     if (!isset($field['pk_i_id']) || isset($field['pk_i_id']) && $field['pk_i_id'] == Params::getParam("id")) {
                         Field::newInstance()->cleanCategoriesFromField(Params::getParam("id"));
                         $slug = Params::getParam("field_slug") != '' ? Params::getParam("field_slug") : Params::getParam("id");
                         $slug = preg_replace('|([-]+)|', '-', preg_replace('|[^a-z0-9_-]|', '-', strtolower($slug)));
                         Field::newInstance()->update(array('s_name' => Params::getParam("s_name"), 'e_type' => Params::getParam("field_type"), 's_slug' => $slug, 'b_required' => Params::getParam("field_required") == "1" ? 1 : 0, 's_options' => Params::getParam('s_options')), array('pk_i_id' => Params::getParam("id")));
                         Field::newInstance()->insertCategories(Params::getParam("id"), Params::getParam("categories"));
                     } else {
                         $error = 1;
                         $message = __("Sorry, you already have one field with that name");
                     }
                 } catch (Exception $e) {
                     $error = 1;
                     $message = __("Error while updating.");
                 }
             }
             $result = "{";
             if ($error) {
                 $result .= '"error" : "';
                 $result .= $message;
                 $result .= '"';
             } else {
                 $result .= '"ok" : "' . __("Saved") . '", "text" : "' . Params::getParam("s_name") . '"';
             }
             $result .= "}";
             echo $result;
             break;
         case 'delete_field':
             $id = Params::getParam("id");
             $error = 0;
             try {
                 $fieldManager = Field::newInstance();
                 $fieldManager->deleteByPrimaryKey($id);
                 $message = __('The custom field have been deleted');
             } catch (Exception $e) {
                 $error = 1;
                 $message = __('Error while deleting');
             }
             $result = "{";
             if ($error) {
                 $result .= '"error" : "';
                 $result .= $message;
                 $result .= '"';
             } else {
                 $result .= '"ok" : "Saved." ';
             }
             $result .= "}";
             echo $result;
             break;
         case 'enable_category':
             $id = Params::getParam("id");
             $enabled = Params::getParam("enabled") != '' ? Params::getParam("enabled") : 0;
             $error = 0;
             $aUpdated = "";
             try {
                 if ($id != '') {
                     $categoryManager = Category::newInstance();
                     $categoryManager->update(array('b_enabled' => $enabled), array('pk_i_id' => $id));
                     if ($enabled == 1) {
                         $msg = __('The category has been enabled');
                     } else {
                         $msg = __('The category has been disabled');
                     }
                     $categoryManager->update(array('b_enabled' => $enabled), array('fk_i_parent_id' => $id));
                     $aUpdated = $categoryManager->listWhere("fk_i_parent_id = {$id}");
                     if ($enabled == 1) {
                         $msg .= "<br>" . __('The subcategories has been enabled');
                     } else {
                         $msg .= "<br>" . __('The subcategories has been disabled');
                     }
                 } else {
                     $error = 1;
                     $msg = __('There was a problem with this page. The ID for the category hasn\'t been set');
                 }
                 $message = $msg;
             } catch (Exception $e) {
                 $error = 1;
                 $message = __('Error: %s') . " " . $e->getMessage();
             }
             $result = "{";
             $error = 0;
             if ($error) {
                 $result .= '"error" : "' . $message . '"';
             } else {
                 $result .= '"ok" : "' . $message . '"';
                 if (count($aUpdated) > 0) {
                     $result .= ', "afectedIds": [';
                     foreach ($aUpdated as $category) {
                         $result .= '{ "id" : "' . $category['pk_i_id'] . '" },';
                     }
                     $result = substr($result, 0, -1);
                     $result .= ']';
                 } else {
                     $result .= ', "afectedIds": []';
                 }
             }
             $result .= "}";
             echo $result;
             break;
         case 'delete_category':
             $id = Params::getParam("id");
             $error = 0;
             try {
                 $categoryManager = Category::newInstance();
                 $categoryManager->deleteByPrimaryKey($id);
                 $message = __('The categories have been deleted');
             } catch (Exception $e) {
                 $error = 1;
                 $message = __('Error while deleting');
             }
             $result = "{";
             if ($error) {
                 $result .= '"error" : "';
                 $result .= $message;
                 $result .= '"';
             } else {
                 $result .= '"ok" : "Saved." ';
             }
             $result .= "}";
             echo $result;
             break;
         case 'edit_category_post':
             $id = Params::getParam("id");
             $fields['i_expiration_days'] = Params::getParam("i_expiration_days") != '' ? Params::getParam("i_expiration_days") : 0;
             $error = 0;
             $postParams = Params::getParamsAsArray();
             foreach ($postParams as $k => $v) {
                 if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                     if ($m[2] == 's_name') {
                         if ($v != "") {
                             $aFieldsDescription[$m[1]][$m[2]] = $v;
                         } else {
                             $error = 1;
                             $message = __("All titles are required");
                         }
                     } else {
                         $aFieldsDescription[$m[1]][$m[2]] = $v;
                     }
                 }
             }
             $l = osc_language();
             if (!$error) {
                 try {
                     $categoryManager = Category::newInstance();
                     $categoryManager->updateByPrimaryKey($fields, $aFieldsDescription, $id);
                 } catch (Exception $e) {
                     $error = 1;
                     $message = __("Error while updating.");
                 }
             }
             $result = "{";
             if ($error) {
                 $result .= '"error" : "';
                 $result .= $message;
                 $result .= '"';
             } else {
                 $result .= '"ok" : "' . __("Saved") . '", "text" : "' . $aFieldsDescription[$l]['s_name'] . '"';
             }
             $result .= "}";
             echo $result;
             break;
         case 'custom':
             // Execute via AJAX custom file
             $ajaxfile = Params::getParam("ajaxfile");
             if ($ajaxfile != '') {
                 require_once osc_admin_base_path() . $ajaxfile;
             } else {
                 echo json_encode(array('error' => __('no action defined')));
             }
             break;
         case 'test_mail':
             $title = __('Test email') . ", " . osc_page_title();
             $body = __("Test email") . "<br><br>" . osc_page_title();
             $emailParams = array('subject' => $title, 'to' => osc_contact_email(), 'to_name' => 'admin', 'body' => $body, 'alt_body' => $body);
             $array = array();
             if (osc_sendMail($emailParams)) {
                 $array = array('status' => '1', 'html' => __('Email sent successfully'));
             } else {
                 $array = array('status' => '0', 'html' => __('An error has occurred while sending email'));
             }
             echo json_encode($array);
             break;
         case 'order_pages':
             $order = Params::getParam("order");
             $id = Params::getParam("id");
             $count = osc_count_static_pages();
             if ($order != '' && $id != '') {
                 $mPages = Page::newInstance();
                 $actual_page = $mPages->findByPrimaryKey($id);
                 $actual_order = $actual_page['i_order'];
                 $array = array();
                 $condition = array();
                 $new_order = $actual_order;
                 if ($order == 'up') {
                     if ($actual_order > 0) {
                         $new_order = $actual_order - 1;
                     }
                 } else {
                     if ($order == 'down') {
                         if ($actual_order != $count - 1) {
                             $new_order = $actual_order + 1;
                         }
                     }
                 }
                 if ($new_order != $actual_order) {
                     $auxpage = $mPages->findByOrder($new_order);
                     $array = array('i_order' => $actual_order);
                     $conditions = array('pk_i_id' => $auxpage['pk_i_id']);
                     $mPages->update($array, $conditions);
                     $array = array('i_order' => $new_order);
                     $conditions = array('pk_i_id' => $id);
                     $mPages->update($array, $conditions);
                 } else {
                 }
                 // json for datatables
                 $prefLocale = osc_current_admin_locale();
                 $aPages = $mPages->listAll(0);
                 $json = "[";
                 foreach ($aPages as $key => $page) {
                     $body = array();
                     if (isset($page['locale'][$prefLocale]) && !empty($page['locale'][$prefLocale]['s_title'])) {
                         $body = $page['locale'][$prefLocale];
                     } else {
                         $body = current($page['locale']);
                     }
                     $p_body = str_replace("'", "\\'", trim(strip_tags($body['s_title']), "\"'"));
                     $json .= "[\"<input type='checkbox' name='id[]' value='" . $page['pk_i_id'] . "' />\",";
                     $json .= "\"" . $page['s_internal_name'] . "<div id='datatables_quick_edit'>";
                     $json .= "<a href='" . osc_static_page_url() . "'>" . __('View page') . "</a> | ";
                     $json .= "<a href='" . osc_admin_base_url(true) . "?page=pages&action=edit&id=" . $page['pk_i_id'] . "'>";
                     $json .= __('Edit') . "</a>";
                     if (!$page['b_indelible']) {
                         $json .= " | ";
                         $json .= "<a onclick=\\\"javascript:return confirm('";
                         $json .= __('This action can\\\\\'t be undone. Are you sure you want to continue?') . "')\\\" ";
                         $json .= " href='" . osc_admin_base_url(true) . "?page=pages&action=delete&id=" . $page['pk_i_id'] . "'>";
                         $json .= __('Delete') . "</a>";
                     }
                     $json .= "</div>\",";
                     $json .= "\"" . $p_body . "\",";
                     $json .= "\"<img id='up' onclick='order_up(" . $page['pk_i_id'] . ");' style='cursor:pointer;width:15;height:15px;' src='" . osc_current_admin_theme_url('images/arrow_up.png') . "'/> <br/> <img id='down' onclick='order_down(" . $page['pk_i_id'] . ");' style='cursor:pointer;width:15;height:15px;' src='" . osc_current_admin_theme_url('images/arrow_down.png') . "'/>\"]";
                     if ($key != count($aPages) - 1) {
                         $json .= ',';
                     } else {
                         $json .= '';
                     }
                 }
                 $json .= "]";
                 echo $json;
             }
             break;
             /******************************
              ** COMPLETE UPGRADE PROCESS **
              ******************************/
         /******************************
          ** COMPLETE UPGRADE PROCESS **
          ******************************/
         case 'upgrade':
             // AT THIS POINT WE KNOW IF THERE'S AN UPDATE OR NOT
             $message = "";
             $error = 0;
             $remove_error_msg = "";
             $sql_error_msg = "";
             $rm_errors = 0;
             $perms = osc_save_permissions();
             osc_change_permissions();
             $maintenance_file = ABS_PATH . '.maintenance';
             $fileHandler = @fopen($maintenance_file, 'w');
             fclose($fileHandler);
             /***********************
              **** DOWNLOAD FILE ****
              ***********************/
             if (Params::getParam('file') != '') {
                 $tmp = explode("/", Params::getParam('file'));
                 $filename = end($tmp);
                 $result = osc_downloadFile(Params::getParam('file'), $filename);
                 if ($result) {
                     // Everything is OK, continue
                     /**********************
                      ***** UNZIP FILE *****
                      **********************/
                     @mkdir(ABS_PATH . 'oc-temp', 0777);
                     $res = osc_unzip_file(osc_content_path() . 'downloads/' . $filename, ABS_PATH . 'oc-temp/');
                     if ($res == 1) {
                         // Everything is OK, continue
                         /**********************
                          ***** COPY FILES *****
                          **********************/
                         $fail = -1;
                         if ($handle = opendir(ABS_PATH . 'oc-temp')) {
                             $fail = 0;
                             while (false !== ($_file = readdir($handle))) {
                                 if ($_file != '.' && $_file != '..' && $_file != 'remove.list' && $_file != 'upgrade.sql' && $_file != 'customs.actions') {
                                     $data = osc_copy(ABS_PATH . "oc-temp/" . $_file, ABS_PATH . $_file);
                                     if ($data == false) {
                                         $fail = 1;
                                     }
                                 }
                             }
                             closedir($handle);
                             if ($fail == 0) {
                                 // Everything is OK, continue
                                 /**********************
                                  **** REMOVE FILES ****
                                  **********************/
                                 if (file_exists(ABS_PATH . 'oc-temp/remove.list')) {
                                     $lines = file(ABS_PATH . 'oc-temp/remove.list', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
                                     foreach ($lines as $line_num => $r_file) {
                                         $unlink = @unlink(ABS_PATH . $r_file);
                                         if (!$unlink) {
                                             $remove_error_msg .= sprintf(__('Error removing file: %s'), $r_file) . "<br/>";
                                         }
                                     }
                                 }
                                 // Removing files is not important for the rest of the proccess
                                 // We will inform the user of the problems but the upgrade could continue
                                 /************************
                                  *** UPGRADE DATABASE ***
                                  ************************/
                                 $error_queries = array();
                                 if (file_exists(osc_lib_path() . 'osclass/installer/struct.sql')) {
                                     $sql = file_get_contents(osc_lib_path() . 'osclass/installer/struct.sql');
                                     $conn = getConnection();
                                     $error_queries = $conn->osc_updateDB(str_replace('/*TABLE_PREFIX*/', DB_TABLE_PREFIX, $sql));
                                 }
                                 if ($error_queries[0]) {
                                     // Everything is OK, continue
                                     /**********************************
                                      ** EXECUTING ADDITIONAL ACTIONS **
                                      **********************************/
                                     if (file_exists(osc_lib_path() . 'osclass/upgrade-funcs.php')) {
                                         // There should be no errors here
                                         define('AUTO_UPGRADE', true);
                                         require_once osc_lib_path() . 'osclass/upgrade-funcs.php';
                                     }
                                     // Additional actions is not important for the rest of the proccess
                                     // We will inform the user of the problems but the upgrade could continue
                                     /****************************
                                      ** REMOVE TEMPORARY FILES **
                                      ****************************/
                                     $path = ABS_PATH . 'oc-temp';
                                     $rm_errors = 0;
                                     $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
                                     for ($dir->rewind(); $dir->valid(); $dir->next()) {
                                         if ($dir->isDir()) {
                                             if ($dir->getFilename() != '.' && $dir->getFilename() != '..') {
                                                 if (!rmdir($dir->getPathname())) {
                                                     $rm_errors++;
                                                 }
                                             }
                                         } else {
                                             if (!unlink($dir->getPathname())) {
                                                 $rm_errors++;
                                             }
                                         }
                                     }
                                     if (!rmdir($path)) {
                                         $rm_errors++;
                                     }
                                     $deleted = @unlink(ABS_PATH . '.maintenance');
                                     if ($rm_errors == 0) {
                                         $message = __('Everything was OK! Your OSClass installation is updated');
                                     } else {
                                         $message = __('Almost everything was OK! Your OSClass installation is updated, but there were some errors removing temporary files. Please, remove manually the "oc-temp" folder');
                                         $error = 6;
                                         // Some errors removing files
                                     }
                                 } else {
                                     $sql_error_msg = $error_queries[2];
                                     $message = __('Problems upgrading the database');
                                     $error = 5;
                                     // Problems upgrading the database
                                 }
                             } else {
                                 $message = __('Problems copying files. Maybe permissions are not correct');
                                 $error = 4;
                                 // Problems copying files. Maybe permissions are not correct
                             }
                         } else {
                             $message = __('Nothing to copy');
                             $error = 99;
                             // Nothing to copy. THIS SHOULD NEVER HAPPENS, means we dont update any file!
                         }
                     } else {
                         $message = __('Unzip failed');
                         $error = 3;
                         // Unzip failed
                     }
                 } else {
                     $message = __('Download failed');
                     $error = 2;
                     // Download failed
                 }
             } else {
                 $message = __('Missing download URL');
                 $error = 1;
                 // Missing download URL
             }
             if ($remove_error_msg != '') {
                 if ($error == 0) {
                     $message .= "<br /><br />" . __('We had some errors removing files, those are not super-sensitive errors, so we continued upgrading your installation. Please remove the following files (you already have OSClass upgraded, but to ensure maximun performance)');
                 }
             }
             if ($error == 5) {
                 $message .= "<br /><br />" . __('We had some errors upgrading your database. The follwing queries failed') . implode("<br />", $sql_error_msg);
             }
             echo $message;
             foreach ($perms as $k => $v) {
                 @chmod($k, $v);
             }
             break;
         default:
             echo json_encode(array('error' => __('no action defined')));
             break;
     }
     // clear all keep variables into session
     Session::newInstance()->_dropKeepForm();
     Session::newInstance()->_clearVariables();
 }