/**
  * 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 $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();
 }
Example #4
0
 /**
  * Generated from @assert (array(1 => 1, 2 => 2, 3 => 'three'), array(1 => 'one', 2 => 'two')) [==] array(1 => 'one', 2 => 'two', 3 => 'three').
  *
  * @covers Kotchasan\ArrayTool::replace
  */
 public function testReplace()
 {
     $this->assertEquals(array(1 => 'one', 2 => 'two', 3 => 'three'), \Kotchasan\ArrayTool::replace(array(1 => 1, 2 => 2, 3 => 'three'), array(1 => 'one', 2 => 'two')));
 }
Example #5
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;
 }
Example #6
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);
     }
 }
Example #7
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;
 }
Example #10
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;
 }