Esempio n. 1
0
 public function processform()
 {
     $types = tpolltypes::i();
     $type = isset($_GET['type']) ? $_GET['type'] : '';
     if (isset($types->items[$type])) {
         foreach ($types->items[$type] as $name => $value) {
             if (isset($_POST[$name])) {
                 $types->items[$type][$name] = $_POST[$name];
             }
         }
         $types->save();
     }
     return '';
 }
 public function getcontent()
 {
     $result = '';
     $polls = tpolls::i();
     $html = tadminhtml::i();
     $lang = tlocal::admin('polls');
     $args = new targs();
     $adminurl = $this->adminurl;
     if ($action = $this->action) {
         $id = $this->idget();
         switch ($action) {
             case 'delete':
                 if ($this->confirmed) {
                     $polls->delete($id);
                     $result .= $html->h4->deleted;
                 } else {
                     $result .= $html->confirmdelete($id, $adminurl, $lang->confirmdelete);
                 }
                 break;
             case 'edit':
                 if (!$polls->itemexists($id)) {
                     $result .= $this->notfound();
                 } else {
                     $result .= sprintf($html->h4->shorttag, $id);
                     $item = $polls->getitem($id);
                     $args->status = $this->getcombostatus($item['status']);
                     $args->id_tml = $this->getcombotml($item['id_tml']);
                     $args->id = $id;
                     $args->formtitle = $lang->editpoll;
                     $result .= $html->adminform('[combo=status]
       [combo=id_tml]
       ', $args);
                 }
                 break;
             case 'add':
                 $args->status = $this->getcombostatus('opened');
                 $args->id_tml = $this->getcombotml(tpollsman::i()->pollpost);
                 $args->formtitle = $lang->addpoll;
                 $result .= $html->adminform('[combo=status]
     [combo=id_tml]
     ', $args);
                 break;
             case 'create':
                 $args->status = $this->getcombostatus('opened');
                 $args->status = '';
                 $args->title = '';
                 $types = array_keys(tpolltypes::i()->items);
                 $args->type = tadminhtml::array2combo(array_combine($types, $types), $types[0]);
                 $args->newitems = '';
                 $args->formtitle = $lang->createpoll;
                 $result .= $html->adminform('[combo=status]
     [text=name]
     [text=title]
     [combo=type]
     [editor=newitems]
     ', $args);
                 break;
         }
     }
     $result .= "<ul>\n    <li><a href='{$adminurl}=0&amp;action=add'>{$lang->addpoll}</a></li>\n    <li><a href='{$adminurl}=0&amp;action=create'>{$lang->createpoll}</a></li>\n    </ul>";
     $args->adminurl = $adminurl;
     $table = '';
     $tr = '<tr>
 <td><a href="$adminurl=$id&amp;action=edit">$name</a></td>
 <td><a href=$adminurl=$id&amp;action=delete">$lang.delete</a></td>
 </tr>';
     $perpage = 20;
     $count = $polls->db->getcount();
     $from = $this->getfrom($perpage, $count);
     $items = $polls->select('', " order by id desc limit {$from}, {$perpage}");
     $result .= sprintf($html->h4->count, $from, $from + count($items), $count);
     foreach ($items as $id) {
         $item = $polls->getitem($id);
         $args->id = $id;
         $args->add($item);
         $tml = $polls->get_tml($item['id_tml']);
         $args->name = $tml['name'];
         $args->title = $tml['title'];
         $table .= $html->parsearg($tr, $args);
     }
     $head = "<tr>\n    <th>{$lang->edit}</th>\n    <th>{$lang->delete}</th>\n    </tr>";
     $result .= $html->gettable($head, $table);
     $theme = ttheme::i();
     $result .= $theme->getpages($this->url, litepublisher::$urlmap->page, ceil($count / $perpage));
     return $result;
 }
 public function getcontent()
 {
     $result = '';
     $polls = tpolls::i();
     $html = tadminhtml::i();
     $lang = tlocal::admin('polls');
     $args = new targs();
     $dir = litepublisher::$paths->data . 'polls';
     $adminurl = $this->adminurl;
     if ($action = $this->action) {
         $id = $this->idget();
         switch ($action) {
             case 'delete':
                 $man = tpollsman::i();
                 if ($id == $man->pollpost) {
                     return $html->h4->deletepullpost;
                 }
                 if ($this->confirmed) {
                     tfilestorage::delete($dir . DIRECTORY_SEPARATOR . "{$id}.php");
                     tfilestorage::delete($dir . DIRECTORY_SEPARATOR . "{$id}.bak.php");
                     unset($polls->tml_items[$id]);
                     $polls->db->update('id_tml = ' . $man->pollpost, "id_tml = {$id}");
                     $result .= $html->h4->deleted;
                 } else {
                     $result .= $html->confirmdelete($id, $adminurl, $lang->confirmdelete);
                 }
                 break;
             case 'edit':
                 if ($tml = $polls->get_tml($id)) {
                     $args->add($tml);
                     $args->id = $id;
                     $args->name = tcontentfilter::unescape($tml['name']);
                     $args->title = tcontentfilter::unescape($tml['title']);
                     //$args->items = implode("\n", $tml['items']);
                     $tabs = new tuitabs();
                     //$tabs->add($lang->pollitems, "[editor=items]");
                     $tabs->add($lang->opened, "[editor=opened]");
                     $tabs->add($lang->closed, "[editor=closed]");
                     $args->formtitle = $lang->edittemplate;
                     $result .= $html->adminform('
       [text=name]
       [text=title]' . $tabs->get(), $args);
                 }
                 break;
             case 'add':
                 $types = array_keys(tpolltypes::i()->items);
                 $args->type = tadminhtml::array2combo(array_combine($types, $types), $types[0]);
                 $args->name = '';
                 $args->title = '';
                 $args->newitems = '';
                 $args->formtitle = $lang->newtemplate;
                 $result .= $html->adminform('[text=name]
     [text=title]
     [combo=type]
     [editor=newitems]', $args);
                 break;
         }
     }
     $result .= $html->h3("<a href='{$adminurl}=0&amp;action=add'>{$lang->addtemplate}</a>");
     $result .= $html->h4->alltemplates;
     $args->adminurl = $adminurl;
     $table = '';
     $tr = '<tr>
 <td><a href="$adminurl=$id&amp;action=edit">$name</a></td>
 <td><a href="$adminurl=$id&amp;action=delete">$lang.delete</a></td>
 </tr>';
     $polls->loadall_tml();
     foreach ($polls->tml_items as $id => $tml) {
         $args->id = $id;
         $args->name = $tml['name'];
         $args->title = $tml['title'];
         $table .= $html->parsearg($tr, $args);
     }
     $head = "<tr>\n    <th>{$lang->edit}</th>\n    <th>{$lang->delete}</th>\n    </tr>";
     $result .= $html->gettable($head, $table);
     return $result;
 }
Esempio n. 4
0
 public function edit_tml($id_tml, $type, $name, $title, array $items)
 {
     $tml_item = tpolltypes::i()->build($type, $name, $title, $items);
     $this->set_tml($id_tml, $tml_item);
 }