/**
  * รับค่าจาก action
  */
 public function action()
 {
     $ret = array();
     // referer, session, admin
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if (empty($login['fb'])) {
             // ค่าที่ส่งมา
             $type = self::$request->post('type')->toString();
             $type = $type == 'js' ? 'js' : 'php';
             $id = self::$request->post('id')->toString();
             $action = self::$request->post('action')->toString();
             if ($action == 'delete') {
                 // โหลดภาษา
                 $datas = Language::installed($type);
                 // ลบรายการที่ส่งมา
                 $datas = ArrayTool::delete($datas, $id);
                 // save
                 $error = Language::save($datas, $type);
                 if (empty($error)) {
                     $ret['location'] = 'reload';
                 } else {
                     $ret['alert'] = $error;
                 }
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     echo json_encode($ret);
 }
 /**
  * module=menuwrite
  *
  * @param object $menu
  * @return string
  */
 public function render($menu)
 {
     // form
     $form = Html::create('form', array('id' => 'setup_frm', 'class' => 'setup_frm', 'autocomplete' => 'off', 'action' => 'index.php/index/model/menuwrite/save', 'onsubmit' => 'doFormSubmit', 'ajax' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Menu details}'));
     $groups = $fieldset->add('groups-table', array('label' => '{LNG_Language}', 'id' => 'language', 'comment' => '{LNG_Select the language of this item (Select the first Is present in every language)}'));
     // language
     $groups->add('select', array('id' => 'language', 'labelClass' => 'g-input icon-language', 'itemClass' => 'width', 'options' => ArrayTool::replace(array('' => '{LNG_all languages}'), Language::installedLanguage()), 'value' => empty($menu->id) ? '' : $menu->language));
     $groups->add('a', array('id' => 'copy_menu', 'class' => 'button icon-copy copy', 'title' => '{LNG_Copy this item to the selected language}'));
     // menu_text
     $fieldset->add('text', array('id' => 'menu_text', 'labelClass' => 'g-input icon-menus', 'itemClass' => 'item', 'label' => '{LNG_Text}', 'comment' => '{LNG_Text displayed on the menu}', 'maxlength' => 100, 'value' => $menu->menu_text));
     // menu_tooltip
     $fieldset->add('text', array('id' => 'menu_tooltip', 'labelClass' => 'g-input icon-edit', 'itemClass' => 'item', 'label' => '{LNG_Tooltip}', 'comment' => '{LNG_Message when mouse over the menu}', 'maxlength' => 100, 'value' => $menu->menu_tooltip));
     // accesskey
     $fieldset->add('text', array('id' => 'accesskey', 'labelClass' => 'g-input icon-keyboard', 'itemClass' => 'item', 'label' => '{LNG_Accesskey}', 'comment' => '{LNG_Enter lowercase English letters or numbers to be used as a shortcut to this menu. (Sub-menus do not support the shortcut menu. Do not duplicate keys of the system shortcut)}', 'value' => $menu->accesskey));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Installation and position of the menu}'));
     // alias
     $fieldset->add('text', array('id' => 'alias', 'labelClass' => 'g-input icon-edit', 'itemClass' => 'item', 'label' => '{LNG_Alias}', 'comment' => '{LNG_The name of the menu (the default is the name of the module is installed)}', 'value' => $menu->alias));
     // parent
     $fieldset->add('select', array('id' => 'parent', 'labelClass' => 'g-input icon-config', 'itemClass' => 'item', 'label' => '{LNG_Menu position}', 'comment' => '{LNG_Select the menu position. The menu will be displayed on the website at the selected position. (Based on templates you are using)}', 'options' => Language::find('MENU_PARENTS', array('MAINMENU' => 'Main menu')), 'value' => $menu->parent));
     // type
     if ($menu->menu_order == 1) {
         $m = 0;
     } elseif ($menu->level == 0) {
         $m = 1;
     } elseif ($menu->level == 1) {
         $m = 2;
     } else {
         $m = 3;
     }
     $fieldset->add('select', array('id' => 'type', 'labelClass' => 'g-input icon-config', 'itemClass' => 'item', 'label' => '{LNG_Menu type}', 'comment' => '{LNG_Select the type of menu}', 'options' => Language::get('MENU_TYPES'), 'value' => $m));
     // menu_order
     $fieldset->add('select', array('id' => 'menu_order', 'labelClass' => 'g-input icon-config', 'itemClass' => 'item', 'label' => '{LNG_Menu order}', 'size' => 8, 'comment' => '{LNG_The sequence of the desired menu. The menu will be displayed next from the selected item}'));
     // published
     $fieldset->add('select', array('id' => 'published', 'labelClass' => 'g-input icon-published1', 'itemClass' => 'item', 'label' => '{LNG_Status}', 'comment' => '{LNG_Publish this item}', 'options' => Language::get('MENU_PUBLISHEDS'), 'value' => $menu->published));
     $fieldset = $form->add('fieldset', array('id' => 'menu_action', 'title' => '{LNG_Action when click on menu}'));
     // action
     if ($menu->menu_url != '') {
         $m = 2;
     } elseif ($menu->index_id == 0) {
         $m = 0;
     } else {
         $m = 1;
     }
     $fieldset->add('select', array('id' => 'action', 'labelClass' => 'g-input icon-config', 'itemClass' => 'item', 'label' => '{LNG_When choosing the menu}', 'comment' => '{LNG_Choose how to proceed. When you click on the menu}', 'options' => Language::get('MENU_ACTIONS'), 'value' => $m));
     // index_id
     $fieldset->add('select', array('id' => 'index_id', 'labelClass' => 'g-input icon-modules', 'itemClass' => 'item action 1', 'label' => '{LNG_installed module}', 'comment' => '{LNG_Choose the page you want to open when you click a menu item from a list of web pages or modules already installed}', 'optgroup' => \Index\Menuwrite\Model::getModules(), 'value' => $menu->owner . '_' . $menu->index_id));
     // menu_url
     $fieldset->add('text', array('id' => 'menu_url', 'labelClass' => 'g-input icon-world', 'itemClass' => 'item action 2', 'label' => '{LNG_URL}', 'comment' => '{LNG_Links for this item, which will open this page when click on it}', 'value' => str_replace(array('{', '}'), array('{', '}'), $menu->menu_url)));
     // menu_target
     $fieldset->add('select', array('id' => 'menu_target', 'labelClass' => 'g-input icon-forward', 'itemClass' => 'item action 1 2', 'label' => '{LNG_The opening page of links}', 'comment' => '{LNG_Determine how to turn the page when a link is clicked}', 'options' => Language::get('MENU_TARGET'), 'value' => $menu->menu_target));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Save}'));
     // id
     $fieldset->add('hidden', array('id' => 'id', 'value' => $menu->id));
     $form->script('initMenuwrite();');
     return $form->render();
 }
 /**
  * อ่านข้อมูลหมวดหมู่ที่เลือก และสามารถเผยแพร่ได้
  *
  * @param int $category_id
  * @param int $module_id
  * @return object|null ข้อมูลที่เลือก (Object) หรือ null หากไม่พบ
  */
 public static function get($category_id, $module_id)
 {
     if (is_int($category_id) && is_int($module_id)) {
         $model = new static();
         $query = $model->db()->createQuery()->select()->from('category')->where(array(array('category_id', $category_id), array('module_id', $module_id), array('published', '1')))->limit(1);
         foreach ($query->toArray()->execute() as $item) {
             $item['topic'] = Gcms::ser2Str($item, 'topic');
             $item['detail'] = Gcms::ser2Str($item, 'detail');
             $item['icon'] = Gcms::ser2Str($item, 'icon');
             return (object) ArrayTool::unserialize($item['config'], $item);
         }
     }
     return null;
 }
 /**
  * ฟังก์ชั่นส่งเมล์จากแม่แบบจดหมาย
  *
  * @param int $id ID ของจดหมายที่ต้องการส่ง
  * @param string $module ชื่อโมดูลของจดหมายที่ต้องการส่ง
  * @param array $datas ข้อมูลที่จะถูกแทนที่ลงในจดหมาย ในรูป 'ตัวแปร'=>'ข้อความ'
  * @param string $to ที่อยู่อีเมล์ผู้รับ  คั่นแต่ละรายชื่อด้วย ,
  * @return string สำเร็จคืนค่าว่าง ไม่สำเร็จ คืนค่าข้อความผิดพลาด
  */
 public static function send($id, $module, $datas, $to)
 {
     $model = new static();
     $email = $model->db()->createQuery()->from('emailtemplate')->where(array(array('module', $module), array('email_id', (int) $id), array('language', array(Language::name(), ''))))->cacheOn()->toArray()->first('from_email', 'copy_to', 'subject', 'detail');
     if ($email === false) {
         return Language::get('email template not found');
     } else {
         // ผู้ส่ง
         $from = empty($email['from_email']) ? self::$cfg->noreply_email : $email['from_email'];
         // ข้อความในอีเมล์
         $replace = ArrayTool::replace(array('/%WEBTITLE%/' => strip_tags(self::$cfg->web_title), '/%WEBURL%/' => WEB_URL, '/%ADMINEMAIL%/' => $from, '/%TIME%/' => Date::format()), $datas);
         ArrayTool::extract($replace, $keys, $values);
         $msg = preg_replace($keys, $values, $email['detail']);
         $subject = preg_replace($keys, $values, $email['subject']);
         $to = explode(',', $to);
         if (!empty($email['copy_to'])) {
             $to[] = $email['copy_to'];
         }
         // ส่งอีเมล์
         return parent::send(implode(',', $to), $from, $subject, $msg);
     }
 }
 /**
  * module=pagewrite
  *
  * @param string $id
  * @return string
  */
 public function render($index)
 {
     // form
     $form = Html::create('form', array('id' => 'setup_frm', 'class' => 'setup_frm', 'autocomplete' => 'off', 'action' => 'index.php/index/model/pagewrite/save', 'onsubmit' => 'doFormSubmit', 'ajax' => true, 'upload' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Details of} ' . Language::get($index->owner === 'index' ? 'Page' : 'Module')));
     $groups = $fieldset->add('groups-table', array('label' => '{LNG_Language}', 'id' => 'language', 'comment' => '{LNG_Select the language of this item (Select the first Is present in every language)}'));
     // language
     $groups->add('select', array('id' => 'language', 'labelClass' => 'g-input icon-language', 'itemClass' => 'width', 'options' => ArrayTool::replace(array('' => '{LNG_all languages}'), Language::installedLanguage()), 'value' => $index->language));
     $groups->add('a', array('id' => 'btn_copy', 'class' => 'button icon-copy copy', 'title' => '{LNG_Copy this item to the selected language}'));
     // module
     $fieldset->add('text', array('id' => 'module', 'labelClass' => 'g-input icon-modules', 'itemClass' => 'item', 'label' => '{LNG_Module}', 'comment' => '{LNG_Name of this module. English lowercase and number only, short. (Can not use a reserve or a duplicate)}', 'maxlength' => 64, 'value' => $index->module));
     // topic
     $fieldset->add('text', array('id' => 'topic', 'labelClass' => 'g-input icon-edit', 'itemClass' => 'item', 'label' => '{LNG_Topic}', 'comment' => '{LNG_Text displayed on the Title Bar of the browser (3 - 255 characters)}', 'maxlength' => 255, 'value' => $index->topic));
     // keywords
     $fieldset->add('textarea', array('id' => 'keywords', 'labelClass' => 'g-input icon-tags', 'itemClass' => 'item', 'label' => '{LNG_Keywords}', 'comment' => '{LNG_Text keywords for SEO or Search Engine to search}', 'value' => $index->keywords));
     // description
     $fieldset->add('textarea', array('id' => 'description', 'labelClass' => 'g-input icon-file', 'itemClass' => 'item', 'label' => '{LNG_Description}', 'comment' => '{LNG_Text short summary of your story. Which can be used to show in your theme. (If not the program will fill in the contents of the first paragraph)}', 'value' => $index->description));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Document', 'upload' => true, 'label' => '{LNG_Detail}', 'value' => $index->detail));
     // published_date
     $fieldset->add('date', array('id' => 'published_date', 'labelClass' => 'g-input icon-calendar', 'itemClass' => 'item', 'label' => '{LNG_Published date}', 'comment' => '{LNG_The date of publication of this information. The publisher will start automatically when you log on due date}', 'value' => $index->published_date));
     // published
     $fieldset->add('select', array('id' => 'published', 'labelClass' => 'g-input icon-published1', 'itemClass' => 'item', 'label' => '{LNG_Published}', 'comment' => '{LNG_Publish this item}', 'options' => Language::get('PUBLISHEDS'), 'value' => $index->published));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Save}'));
     // preview button
     if ($index->owner == 'index') {
         $fieldset->add('button', array('id' => 'btn_preview', 'class' => 'button preview large', 'value' => '{LNG_Preview}'));
     }
     // owner
     $fieldset->add('hidden', array('id' => 'owner', 'value' => $index->owner));
     // id
     $fieldset->add('hidden', array('id' => 'id', 'value' => $index->id));
     $form->script('initIndexWrite();');
     return $form->render();
 }
Beispiel #6
0
 /**
  * Generated from @assert (array(1 => 'one', 2 => 'two'), 3, 3, 'three') [==] array(1 => 'one', 2 => 'two', 3 => 'three').
  *
  * @covers Kotchasan\ArrayTool::insertAfter
  */
 public function testInsertAfter3()
 {
     $this->assertEquals(array(1 => 'one', 2 => 'two', 3 => 'three'), \Kotchasan\ArrayTool::insertAfter(array(1 => 'one', 2 => 'two'), 3, 3, 'three'));
 }
Beispiel #7
0
 /**
  * ฟังก์ชั่นสร้างคำสั่ง WHERE
  *
  * @param mixed $condition query string หรือ array
  * @param string $oprator defaul AND
  * @param string $id Primary Key เช่น id (default)
  * @return \static
  *
  * @assert where(1)->text() [==] " WHERE `id` = 1"
  * @assert where(array('id', 1))->text() [==] " WHERE `id` = 1"
  * @assert where(array('id', '1'))->text() [==] " WHERE `id` = '1'"
  * @assert where(array('date', '2016-1-1 30:30'))->text() [==] " WHERE `date` = '2016-1-1 30:30'"
  * @assert where(array('id', '=', 1))->text() [==] " WHERE `id` = 1"
  * @assert where('`id`=1 OR (SELECT ....)')->text() [==] " WHERE `id`=1 OR (SELECT ....)"
  * @assert where(array('id', '=', 1))->text() [==] " WHERE `id` = 1"
  * @assert where(array('id', 'IN', array(1, 2, '3')))->text() [==] " WHERE `id` IN (1, 2, '3')"
  * @assert where(array('(...)', array('fb', '0')))->text() [==] " WHERE (...) AND `fb` = '0'"
  * @assert where(array(array('fb', '0'), '(...)'))->text() [==] " WHERE `fb` = '0' AND (...)"
  * @assert where(array(array('MONTH(create_date)', 1), array('YEAR(create_date)', 1)))->text() [==] " WHERE MONTH(create_date) = 1 AND YEAR(create_date) = 1"
  * @assert where(array(array('id', array(1, 'a')), array('id', array('G.id', 'G.`id2`'))))->text() [==] " WHERE `id` IN (1, 'a') AND `id` IN (G.`id`, G.`id2`)"
  * @assert where(array('ip', 'NOT IN', array('', '192.168.1.104')))->text() [==] " WHERE `ip` NOT IN ('', '192.168.1.104')"
  */
 public function where($condition, $oprator = 'AND', $id = 'id')
 {
     $ret = $this->buildWhere($condition, $oprator, $id);
     if (is_array($ret)) {
         $this->sqls['where'] = $ret[0];
         $this->values = ArrayTool::replace($this->values, $ret[1]);
     } else {
         $this->sqls['where'] = $ret;
     }
     return $this;
 }
 /**
  * สร้างตาราง และเริ่มต้นทำงานตาราง
  * คืนค่าเป็นโค้ด HTML ของ DataTable
  *
  * @return string
  */
 public function render()
 {
     if (!empty($this->actions) && $this->checkCol == -1) {
         $this->checkCol = 1;
     }
     $url_query = array();
     $hidden_fields = array();
     foreach (self::$request->getQueryParams() as $key => $value) {
         $value = rawurlencode($value);
         $url_query[$key] = $key . '=' . $value;
         // แอเรย์เก็บรายการ input ที่ไม่ต้องสร้าง
         if ($key !== 'search' && $key !== 'count' && $key !== 'page' && $key !== 'action') {
             $hidden_fields[$key] = '<input type="hidden" name="' . $key . '" value="' . $value . '">';
         }
     }
     if (isset($this->model)) {
         // รายการ Query หลัก (AND)
         $qs = array();
         foreach ($this->defaultFilters as $array) {
             $qs[] = $array;
         }
     }
     // create HTML
     $content = array('<div class="datatable" id="' . $this->id . '">');
     // form
     $form = array();
     if (isset($this->perPage)) {
         $entries = Language::get('entries');
         $form[] = $this->addFilter(array('name' => 'count', 'text' => Language::get('Show'), 'value' => $this->perPage, 'options' => array(10 => '10 ' . $entries, 20 => '20 ' . $entries, 30 => '30 ' . $entries, 40 => '40 ' . $entries, 50 => '50 ' . $entries, 100 => '100 ' . $entries)));
     }
     // รายการ Query กำหนดโดย User (AND)
     foreach ($this->filters as $key => $items) {
         $form[] = $this->addFilter($items);
         unset($hidden_fields[$items['name']]);
         if (!isset($items['default'])) {
             $items['default'] = '';
         }
         // ไม่ Query รายการ default
         if (!empty($items['options']) && isset($items['value']) && $items['value'] !== $items['default'] && in_array($items['value'], array_keys($items['options']), true)) {
             $qs[] = array($key, $items['value']);
         }
     }
     // ปุ่ม Go
     if (!empty($form)) {
         $form[] = '<fieldset>';
         $form[] = '<input type=submit class="button go" value="' . Language::get('Go') . '">';
         $form[] = implode('', $hidden_fields);
         $form[] = '</fieldset>';
     }
     // search
     $search = self::$request->request('search')->text();
     if (!empty($this->searchColumns)) {
         if (!empty($search)) {
             if (isset($this->model)) {
                 $sh = array();
                 foreach ($this->searchColumns as $key) {
                     $sh[] = array($key, 'LIKE', "%{$search}%");
                 }
                 $qs[] = $this->rs->group($sh, 'OR');
             } elseif (isset($this->datas)) {
                 // filter ข้อมูลจาก array
                 $this->datas = ArrayTool::filter($this->datas, $search);
             }
         }
         $form[] = '&nbsp;<fieldset class=search>';
         $form[] = '<label accesskey=f class="icon-search"><input type=text name=search value="' . $search . '" placeholder="' . Language::get('Search') . '"></label>';
         $form[] = '<input type=submit value="&nbsp;">';
         $form[] = '</fieldset>';
     }
     if (!empty($form)) {
         $content[] = '<form class="table_nav" method="get">' . implode('', $form) . '</form>';
     }
     if (isset($this->model)) {
         // Model
         $query = $this->rs->where($qs)->toArray();
         if ($this->cache) {
             $this->rs->cacheOn();
         }
         // จำนวนข้อมูลทั้งหมด
         $count = $this->rs->count();
     } elseif (!empty($this->datas)) {
         // จำนวนข้อมูลใน array
         $count = sizeof($this->datas);
     } else {
         $count = 0;
     }
     // การแบ่งหน้า
     if (empty($this->perPage)) {
         $start = 0;
         $totalpage = 1;
         $page = 1;
         $s = 1;
         $e = $count;
         $this->perPage = 0;
     } else {
         // หน้าที่เลือก
         $page = max(1, self::$request->request('page', 1)->toInt());
         // ตรวจสอบหน้าที่เลือกสูงสุด
         $totalpage = round($count / $this->perPage);
         $totalpage += $totalpage * $this->perPage < $count ? 1 : 0;
         $page = max(1, $page > $totalpage ? $totalpage : $page);
         $start = $this->perPage * ($page - 1);
         // คำนวณรายการที่แสดง
         $s = $start < 0 ? 0 : $start + 1;
         $e = min($count, $s + $this->perPage - 1);
     }
     // table caption
     if ($this->showCaption) {
         if (empty($search)) {
             $caption = Language::get('All :count entries, displayed :start to :end, page :page of :total pages');
         } else {
             $caption = Language::get('Search <strong>:search</strong> found :count entries, displayed :start to :end, page :page of :total pages');
         }
         $caption = str_replace(array(':search', ':count', ':start', ':end', ':page', ':total'), array($search, number_format($count), number_format($s), number_format($e), number_format($page), number_format($totalpage)), $caption);
     }
     // เรียงลำดับ
     if (!empty($this->sort)) {
         $sorts = array();
         foreach (explode(',', $this->sort) as $sort) {
             if (preg_match('/^([a-z0-9_\\-]+)([\\s]+(desc|asc))?$/i', trim($sort), $match)) {
                 if (isset($this->headers[$match[1]]['sort'])) {
                     $sort = $this->headers[$match[1]]['sort'];
                 } elseif (isset($this->columns[$match[1]])) {
                     $sort = $match[1];
                 } elseif (isset($this->rs) && $this->rs->fieldExists($match[1])) {
                     $sort = $match[1];
                 } else {
                     $sort = null;
                 }
                 if ($sort) {
                     $sortType = isset($match[3]) && strtolower($match[3]) == 'desc' ? 'desc' : 'asc';
                     $this->sorts[$sort] = $sortType;
                     $sorts[] = $sort . ' ' . $sortType;
                 }
             }
         }
         $this->sort = implode(',', $sorts);
         if (isset($this->model)) {
             if (!empty($sorts)) {
                 $query->order($sorts);
             }
         } elseif (!empty($this->sorts)) {
             reset($this->sorts);
             $sort = key($this->sorts);
             $this->datas = ArrayTool::sort($this->datas, $sort, $this->sorts[$sort]);
         }
     }
     if (isset($this->model)) {
         // query ข้อมูล
         $this->datas = $this->rs->take($start, $this->perPage)->execute($this->fields);
         // รายการสุดท้าย
         $end = $this->perPage + 1;
         // รายการแรก
         $start = -1;
     } elseif (isset($this->datas)) {
         // รายการสุดท้าย
         $end = $start + $this->perPage - 1;
         // รายการแรก
         $start = $start - 2;
     } else {
         $end = 0;
     }
     if (!empty($this->headers)) {
         // property ของ ตาราง
         $prop = array();
         $c = array();
         if (isset($this->class)) {
             $c[] = $this->class;
         }
         if ($this->border) {
             $c[] = 'border';
         }
         if ($this->responsive) {
             $c[] = 'responsive-v';
         }
         if ($this->fullWidth) {
             $c[] = 'fullwidth';
         }
         if (sizeof($c) > 0) {
             $prop[] = ' class="' . implode(' ', $c) . '"';
         }
         // table
         $content[] = '<div class="tablebody"><table' . implode('', $prop) . '>';
         if ($this->showCaption) {
             $content[] = '<caption>' . $caption . '</caption>';
         }
         $row = array();
         $i = 0;
         $colCount = 0;
         $colspan = 0;
         foreach ($this->headers as $key => $attributes) {
             if ($colspan === 0) {
                 if ($i == $this->checkCol) {
                     $row[] = '<th class="check-column"><a class="checkall icon-uncheck"></a></th>';
                     $colCount++;
                 }
                 if ($i == $this->dragColumn) {
                     $row[] = '<th></th>';
                     $colCount++;
                 }
                 if (isset($attributes['colspan'])) {
                     $colspan = $attributes['colspan'] - 1;
                 }
                 $row[] = $this->th($i, $key, $attributes);
                 $colCount++;
                 $i++;
             } else {
                 $colspan--;
             }
         }
         if (!empty($this->buttons)) {
             $row[] = $this->th($i, '', array('text' => ''));
             $colCount++;
             $i++;
         }
         if ($this->pmButton) {
             $row[] = $this->th($i, '', array('text' => ''));
             $colCount++;
         }
         // thead
         $content[] = '<thead><tr>' . implode('', $row) . '</tr></thead>';
         // tbody
         if (!empty($this->datas)) {
             $content[] = '<tbody>' . $this->tbody($start, $end) . '</tbody>';
         }
         // tfoot
         if ($this->checkCol > -1) {
             $row = array();
             $row[] = '<td colspan="' . $this->checkCol . '"></td>';
             $row[] = '<td class="check-column"><a class="checkall icon-uncheck"></a></td>';
             $row[] = '<td colspan="' . ($colCount - $this->checkCol - 1) . '"></td>';
             $content[] = '<tfoot><tr>' . implode('', $row) . '</tr></tfoot>';
         }
         $content[] = '</table></div>';
         $table_nav = array();
         foreach ($this->actions as $item) {
             $table_nav[] = $this->addAction($item);
         }
         if (!empty($this->addNew)) {
             $prop = array();
             foreach ($this->addNew as $k => $v) {
                 $prop[$k] = $k . '="' . $v . '"';
             }
             if (preg_match('/^((.*)\\s+)?(icon-[a-z0-9\\-_]+)(\\s+(.*))?$/', $this->addNew['class'], $match)) {
                 $prop['class'] = 'class="' . trim($match[2] . ' ' . (isset($match[5]) ? $match[5] : '')) . '"';
                 $table_nav[] = '<a ' . implode(' ', $prop) . '><span class="' . $match[3] . '">' . (isset($this->addNew['text']) ? $this->addNew['text'] : '') . '</span></a>';
             } else {
                 $table_nav[] = '<a ' . implode(' ', $prop) . '>' . (isset($this->addNew['text']) ? $this->addNew['text'] : '') . '</a>';
             }
         }
         if (!empty($table_nav)) {
             $content[] = '<div class="table_nav action">' . implode('', $table_nav) . '</div>';
         }
         // แบ่งหน้า
         if (!empty($this->perPage)) {
             $content[] = '<div class="splitpage">' . self::$request->getUri()->pagination($totalpage, $page) . '</div>';
         }
     }
     $content[] = '</div>';
     $script = array('page' => $page, 'search' => $search, 'sort' => $this->sort, 'action' => $this->action, 'actionCallback' => $this->actionCallback, 'actionConfirm' => $this->actionConfirm, 'pmButton' => $this->pmButton, 'dragColumn' => $this->dragColumn);
     $this->javascript[] = 'var table = new GTable("' . $this->id . '", ' . json_encode($script) . ');';
     $content[] = "<script>\n" . implode("\n", $this->javascript) . "\n</script>";
     return implode("\n", $content);
 }
Beispiel #9
0
 /**
  * ฟังก์ชั่นแก้ไขข้อมูล
  *
  * @param string $table_name ชื่อตาราง
  * @param mixed $condition query WHERE
  * @param array|object $save ข้อมูลที่ต้องการบันทึก รูปแบบ array('key1'=>'value1', 'key2'=>'value2', ...)
  * @return boolean สำเร็จ คืนค่า true, ผิดพลาด คืนค่า false
  */
 public function update($table_name, $condition, $save)
 {
     $sets = array();
     $values = array();
     foreach ($save as $key => $value) {
         $sets[] = '`' . $key . '` = :_' . $key;
         $values[':_' . $key] = $value instanceof QueryBuilder ? '(' . $value->text() . ')' : $value;
     }
     $condition = $this->buildWhere($condition);
     if (is_array($condition)) {
         $values = ArrayTool::replace($values, $condition[1]);
         $condition = $condition[0];
     }
     $sql = 'UPDATE ' . $table_name . ' SET ' . implode(', ', $sets) . ' WHERE ' . $condition;
     try {
         $query = $this->connection->prepare($sql);
         $query->execute($values);
         $this->log(__FUNCTION__, $sql, $values);
         self::$query_count++;
         return true;
     } catch (PDOException $e) {
         throw new Exception($e->getMessage(), 500, $e);
     }
 }
Beispiel #10
0
 /**
  * WHERE ....
  * int ค้นหาจาก primaryKey เช่น id=1 หมายถึง WHERE `id`=1
  * string เช่น QUERY ต่างๆ `email`='xxx.com' หมายถึง WHERE `email`='xxx.com'
  * array เช่น ('id', 1) หมายถึง WHERE `id`=1
  * array เช่น ('email', '!=', 'xxx.com') หมายถึง WHERE `email`!='xxx.com'
  * ถ้าเป็น array สามารถรุบได้หลายค่าโดยแต่ละค่าจะเชื่อมด้วย $oprator
  *
  * @param mixed $where
  * @param string $oprator (options) AND (default), OR
  * @return \static
  */
 public function where($where = array(), $oprator = 'AND')
 {
     if (is_int($where) || is_string($where) && $where != '' || is_array($where) && !empty($where)) {
         $where = $this->buildWhere($where, $oprator, $this->field->table_alias . '.' . $this->field->getPrimarykey());
         if (is_array($where)) {
             $this->values = ArrayTool::replace($this->values, $where[1]);
             $where = $where[0];
         }
         $this->sqls['where'] = $where;
     }
     return $this;
 }
 /**
  * ฟังก์ชั่นสร้างคำสั่ง WHERE และ values ไม่ใส่ alias ให้กับชื่อฟิลด์
  *
  * @param mixed $condition
  * @param string $operator (optional) เช่น AND หรือ OR
  * @param string $id (optional )ชื่อฟิลด์ที่เป็น key
  * @return array ($condition, $values)
  */
 protected function buildWhereValues($condition, $operator = 'AND', $id = 'id')
 {
     if (is_array($condition)) {
         $values = array();
         $qs = array();
         if (is_array($condition[0])) {
             foreach ($condition as $item) {
                 $ret = $this->buildWhereValues($item, $operator, $id);
                 $qs[] = $ret[0];
                 $values = ArrayTool::replace($values, $ret[1]);
             }
             $condition = implode(' ' . $operator . ' ', $qs);
         } elseif (strpos($condition[0], '(') !== false) {
             $condition = $condition[0];
         } else {
             if (sizeof($condition) == 2) {
                 $condition = array($condition[0], '=', $condition[1]);
             } else {
                 $condition[1] = strtoupper(trim($condition[1]));
             }
             if (is_array($condition[2])) {
                 $operator = $condition[1] == '=' ? 'IN' : $condition[1];
                 $qs = array();
                 foreach ($condition[2] as $k => $v) {
                     $qs[] = ":{$condition['0']}{$k}";
                     $values[":{$condition['0']}{$k}"] = $v;
                 }
                 $condition = $this->fieldName($condition[0]) . ' ' . $operator . ' (' . implode(',', $qs) . ')';
             } else {
                 $values[":{$condition['0']}"] = $condition[2];
                 $condition = $this->fieldName($condition[0]) . ' ' . $condition[1] . ' :' . $condition[0];
             }
         }
     } elseif (is_numeric($condition)) {
         // primaryKey
         $values = array(":{$id}" => $condition);
         $condition = "`{$id}` = :{$id}";
     } else {
         $values = array();
     }
     return array($condition, $values);
 }
 /**
  * ฟังก์ชั่นประมวลผลคำสั่ง SQL จาก query builder
  *
  * @param array $sqls
  * @param array $values ถ้าระบุตัวแปรนี้จะเป็นการบังคับใช้คำสั่ง prepare แทน query
  * @return mixed
  */
 public function execQuery($sqls, $values = array())
 {
     $sql = $this->makeQuery($sqls);
     if (isset($sqls['values'])) {
         $values = ArrayTool::replace($sqls['values'], $values);
     }
     if ($sqls['function'] == 'customQuery') {
         $result = $this->customQuery($sql, true, $values);
     } else {
         $result = $this->query($sql, $values);
     }
     return $result;
 }
 /**
  * action ของตารางหมวดหมู่
  */
 public function action()
 {
     // referer, session, member
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             echo Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $id = self::$request->post('id')->toString();
             $value = self::$request->post('value')->toInt();
             if (preg_match('/^category_([0-9]+)$/', $id, $match)) {
                 $action = 'category';
                 $module_id = (int) $match[1];
             } else {
                 $action = self::$request->post('action')->toString();
                 $module_id = self::$request->post('mid')->toInt();
             }
             // ตรวจสอบโมดูล
             $index = false;
             if (!empty($module_id)) {
                 $index = \Index\Module\Model::getModule($module_id);
             }
             if ($action === 'category') {
                 // อ่านข้อมูลหมวดหมู่ตอนเขียนบทความ
                 $category = $this->db()->first($this->getFullTableName('category'), array(array('category_id', (int) $value), array('module_id', (int) $index->id)));
                 if ($category) {
                     $config = @unserialize($category->config);
                     if (!is_array($config)) {
                         $config = array('can_reply' => 0);
                     }
                     $ret = array('can_reply' => empty($config['can_reply']) ? 0 : 1, 'published' => empty($category->published) ? 0 : 1);
                     // คืนค่าเป็น JSON
                     echo json_encode($ret);
                 }
             } elseif ($index && Gcms::canConfig($login, $index, 'can_config')) {
                 if ($action === 'delete' && preg_match('/^[0-9,]+$/', $id)) {
                     // ลบหมวด
                     $query = $this->db()->createQuery()->select('id', 'icon')->from('category')->where(array(array('id', explode(',', $id)), array('module_id', $index->id)))->toArray();
                     $ids = array();
                     foreach ($query->execute() as $item) {
                         $ids[] = $item['id'];
                         foreach (ArrayTool::unserialize($item['icon']) as $icon) {
                             @unlink(ROOT_PATH . DATA_FOLDER . $item['owner'] . '/' . $icon);
                         }
                     }
                     if (!empty($ids)) {
                         // ลบหมวดหมู่
                         $this->db()->createQuery()->delete('category', array(array('id', $ids), array('module_id', $index->id)))->execute();
                     }
                 } else {
                     $category = $this->db()->first($this->getFullTableName('category'), array(array('id', (int) $id), array('module_id', (int) $index->id)));
                     if ($category) {
                         if ($action === 'categoryid') {
                             // แก้ไข category_id หน้ารายการหมวดหมู่
                             // ค้นหาหมวดหมู่ซ้ำ
                             $search = $this->db()->createQuery()->from('category')->where(array(array('module_id', (int) $index->id), array('category_id', $value)))->first('id');
                             if ($search) {
                                 // มี category_id อยู่ก่อนแล้วคืนค่ารายการเดิม
                                 $ret['categoryid_' . $index->id . '_' . $category->id] = $category->category_id;
                             } else {
                                 // save
                                 $this->db()->createQuery()->update('category')->set(array('category_id' => $value))->where((int) $category->id)->execute();
                                 // คืนค่ารายการใหม่
                                 $ret['categoryid_' . $index->id . '_' . $category->id] = $value;
                             }
                         } elseif ($action === 'published' || $action === 'can_reply') {
                             // เผยแพร่, การแสดงความคิดเห็น
                             if ($action === 'can_reply') {
                                 $config = @unserialize($category->config);
                                 if (!is_array($config)) {
                                     $config = array();
                                 }
                                 $config['can_reply'] = empty($config['can_reply']) ? 1 : 0;
                                 $save = array('config' => serialize($config));
                                 // คืนค่า
                                 $ret['elem'] = 'can_reply_' . $category->id;
                                 $lng = Language::get('REPLIES');
                                 $ret['title'] = $lng[$config['can_reply']];
                                 $ret['class'] = 'icon-reply reply' . $config['can_reply'];
                             } else {
                                 $save = array('published' => $category->published == 1 ? 0 : 1);
                                 // คืนค่า
                                 $ret['elem'] = 'published_' . $category->id;
                                 $lng = Language::get('PUBLISHEDS');
                                 $ret['title'] = $lng[$save['published']];
                                 $ret['class'] = 'icon-published' . $save['published'];
                             }
                             $this->db()->update($this->getFullTableName('category'), $category->id, $save);
                         }
                         // คืนค่าเป็น JSON
                         echo json_encode($ret);
                     }
                 }
             }
         }
     } else {
         echo Language::get('Unable to complete the transaction');
     }
 }
Beispiel #14
0
 /**
  * โหลดไฟล์ภาษาทั้งหมดที่ติดตั้ง
  * คืนค่าข้อมูลภาษาทั้งหมด
  *
  * @param string $type
  * @return array
  */
 public static function installed($type)
 {
     $language_folder = self::languageFolder();
     $datas = array();
     foreach (self::installedLanguage() as $lng) {
         if ($type == 'php') {
             if (is_file($language_folder . $lng . '.php')) {
                 // php
                 $datas[$lng] = (include $language_folder . $lng . '.php');
             }
         } elseif (is_file($language_folder . $lng . '.js')) {
             // js
             $list = file($language_folder . $lng . '.js');
             foreach ($list as $item) {
                 if (preg_match('/var\\s+(.*)\\s+=\\s+[\'"](.*)[\'"];/', $item, $values)) {
                     $datas[$lng][$values[1]] = $values[2];
                 }
             }
         }
     }
     // จัดกลุ่มภาษาตาม key
     $languages = array();
     foreach ($datas as $language => $values) {
         foreach ($values as $key => $value) {
             $languages[$key][$language] = $value;
             if (is_array($value)) {
                 $languages[$key]['array'] = true;
             }
         }
     }
     // จัดกลุามภาษาตาม id
     $datas = array();
     $i = 0;
     foreach ($languages as $key => $row) {
         $datas[$i] = ArrayTool::replace(array('id' => $i, 'key' => $key), $row);
         $i++;
     }
     return $datas;
 }
 /**
  * อ่านข้อมูลโมดูลจาก $module และ $owner
  *
  * @param string $owner
  * @param string $module
  * @param int $module_id
  * @return object|false คืนค่าข้อมูลโมดูล (Object) ไม่พบคืนค่า false
  */
 public static function get($owner, $module, $module_id = 0)
 {
     // Model
     $model = new static();
     if (empty($module_id)) {
         $where = array(array('module', $module), array('owner', $owner));
     } else {
         $where = array(array('id', (int) $module_id), array('owner', $owner));
     }
     $module = $model->db()->createQuery()->from('modules')->where($where)->toArray()->cacheOn()->first('id module_id', 'module', 'config');
     if ($module) {
         $module = ArrayTool::unserialize($module['config'], $module);
         unset($module['config']);
         return (object) $module;
     }
     return false;
 }