コード例 #1
0
 public function pjActionUpdate()
 {
     $this->checkLogin();
     if ($this->isAdmin() || $this->isEditor()) {
         if (isset($_POST['location_update'])) {
             $data = array();
             if (empty($_POST['lat']) && empty($_POST['lng'])) {
                 $data = pjAppController::getCoords($_POST['i18n'][$this->getLocaleId()]['address']);
             }
             pjLocationModel::factory()->where('id', $_POST['id'])->limit(1)->modifyAll(array_merge($_POST, $data));
             if (isset($_POST['i18n'])) {
                 pjMultiLangModel::factory()->updateMultiLang($_POST['i18n'], $_POST['id'], 'pjLocation', 'data');
             }
             $pjLocationCoordModel = pjLocationCoordModel::factory();
             $pjLocationCoordModel->where('location_id', $_POST['id'])->eraseAll();
             if (isset($_POST['data'])) {
                 foreach ($_POST['data'] as $type => $coords) {
                     foreach ($coords as $hash => $d) {
                         $pjLocationCoordModel->reset()->setAttributes(array('location_id' => $_POST['id'], 'type' => $type, 'hash' => md5($hash), 'data' => $d))->insert();
                     }
                 }
             }
             pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionUpdate&id=" . $_POST['id'] . "&err=AL01");
         } else {
             $arr = pjLocationModel::factory()->find($_GET['id'])->getData();
             if (count($arr) === 0) {
                 pjUtil::redirect(PJ_INSTALL_URL . "index.php?controller=pjAdminLocations&action=pjActionIndex&err=AL08");
             }
             $arr['i18n'] = pjMultiLangModel::factory()->getMultiLang($arr['id'], 'pjLocation');
             $this->set('arr', $arr);
             $this->set('coord_arr', pjLocationCoordModel::factory()->where('location_id', $_GET['id'])->findAll()->getData());
             $locale_arr = pjLocaleModel::factory()->select('t1.*, t2.file')->join('pjLocaleLanguage', 't2.iso=t1.language_iso', 'left')->where('t2.file IS NOT NULL')->orderBy('t1.sort ASC')->findAll()->getData();
             $lp_arr = array();
             foreach ($locale_arr as $item) {
                 $lp_arr[$item['id'] . "_"] = $item['file'];
             }
             $this->set('lp_arr', $locale_arr);
             $this->set('locale_str', pjAppController::jsonEncode($lp_arr));
             $this->appendJs('jquery.validate.min.js', PJ_THIRD_PARTY_PATH . 'validate/');
             $this->appendJs('jquery.multilang.js', PJ_FRAMEWORK_LIBS_PATH . 'pj/js/');
             $this->appendJs('jquery.tipsy.js', PJ_THIRD_PARTY_PATH . 'tipsy/');
             $this->appendCss('jquery.tipsy.css', PJ_THIRD_PARTY_PATH . 'tipsy/');
             $this->appendJs('js?sensor=false&libraries=drawing', 'https://maps.googleapis.com/maps/api/', TRUE);
             $this->appendJs('pjAdminLocations.js');
         }
     } else {
         $this->set('status', 2);
     }
 }
コード例 #2
0
 public function pjActionGetLocations()
 {
     $this->setAjax(true);
     if ($this->isXHR()) {
         $pjLocationCoordModel = pjLocationCoordModel::factory();
         $arr = pjLocationModel::factory()->join('pjMultiLang', "t2.foreign_id = t1.id AND t2.model = 'pjLocation' AND t2.locale = '" . $this->getLocaleId() . "' AND t2.field = 'name'", 'left')->join('pjMultiLang', "t3.foreign_id = t1.id AND t3.model = 'pjLocation' AND t3.locale = '" . $this->getLocaleId() . "' AND t3.field = 'address'", 'left')->select('t1.*, t2.content AS name, t3.content AS address')->findAll()->getData();
         foreach ($arr as $k => $v) {
             $arr[$k]['coords'] = $pjLocationCoordModel->reset()->where('t1.location_id', $v['id'])->findAll()->getData();
         }
         pjAppController::jsonResponse($arr);
     }
     exit;
 }