예제 #1
0
 public function fetchElement($name)
 {
     static $sid = 0;
     $selected = 0;
     $db = SPFactory::db();
     if (!$sid) {
         $sid = 0;
         if ($this->cid) {
             $link = $this->getLink();
             if (strstr($link, 'sid')) {
                 $query = array();
                 parse_str($link, $query);
                 $sid = $query['sid'];
                 if (isset($query['sptpl'])) {
                     $this->tpl = $query['sptpl'];
                 }
             }
             if ($sid) {
                 $section = SPFactory::object($sid);
                 if ($section->oType == 'section') {
                     $selected = $section->id;
                     $this->section = $selected;
                 } else {
                     $path = array();
                     $id = $sid;
                     while ($id > 0) {
                         try {
                             $db->select('pid', 'spdb_relations', array('id' => $id));
                             $id = $db->loadResult();
                             if ($id) {
                                 $path[] = (int) $id;
                             }
                         } catch (SPException $x) {
                         }
                     }
                     $path = array_reverse($path);
                     $selected = $path[0];
                     $this->section = $selected;
                 }
             } else {
                 // just to not repeating
                 $sid = -1;
             }
         }
     }
     $this->sid = $sid;
     $this->determineObjectType($sid);
     switch ($name) {
         case 'sid':
             $params = array('id' => 'sid', 'class' => 'input-mini', 'style' => 'text-align: center; margin-top: 10px; margin-left: 10px;', 'readonly' => 'readonly');
             return '<div class="SobiPro" id="jform_request_sid">' . SPHtml_Input::text('type', $this->oTypeName, array('id' => 'otype', 'class' => 'input-medium', 'style' => 'text-align: center; margin-top: 10px;', 'readonly' => 'readonly')) . SPHtml_Input::text('urlparams[sid]', $sid, $params) . '</div>';
             break;
         case 'cid':
             return $this->getCat();
             break;
         case 'eid':
             return $this->getEntry();
             break;
         case 'did':
         case 'date':
             return $this->getCalendar();
             break;
         case 'tpl':
         case 'sptpl':
             return $this->getTemplates();
             break;
     }
     $sections = array();
     $sout = array();
     try {
         $sections = $db->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     if (count($sections)) {
         SPLoader::loadClass('models.datamodel');
         SPLoader::loadClass('models.dbobject');
         SPLoader::loadModel('section');
         $sout[] = Sobi::Txt('SOBI_SELECT_SECTION');
         foreach ($sections as $section) {
             if (Sobi::Can('section', 'access', 'valid', $section->id)) {
                 $s = new SPSection();
                 $s->extend($section);
                 $sout[$s->get('id')] = $s->get('name');
             }
         }
     }
     $params = array('id' => 'spsection', 'class' => 'required');
     $field = SPHtml_Input::select('sid', $sout, $selected, false, $params);
     return "<div class=\"SobiPro\" style=\"margin-top: 2px;\">{$field}</div>";
 }
예제 #2
-2
 protected function loadSection()
 {
     $sections = array();
     $sectionsOutput = array();
     try {
         $sections = SPFactory::db()->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     if (count($sections)) {
         $sectionsOutput[] = Sobi::Txt('SOBI_SELECT_SECTION');
         foreach ($sections as $section) {
             if (Sobi::Can('section', 'access', 'valid', $section->id)) {
                 $s = new SPSection();
                 $s->extend($section);
                 $sectionsOutput[$s->get('id')] = $s->get('name');
             }
         }
     }
     $params = array('id' => 'SobiSection', 'class' => 'required');
     return SPHtml_Input::select('section', $sectionsOutput, self::$section, false, $params);
 }