/**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // ภาษาที่ต้องการ
         $language = self::$request->get('language', Language::name())->toString();
         if (preg_match('/^[a-z]{2,2}$/', $language)) {
             // maintenance detail
             $template = ROOT_PATH . DATA_FOLDER . 'maintenance.' . $language . '.php';
             if (is_file($template)) {
                 $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
             } else {
                 $template = '<p style="padding: 20px; text-align: center; font-weight: bold;">Website Temporarily Closed for Maintenance, Please try again in a few minutes.<br>ปิดปรับปรุงเว็บไซต์ชั่วคราวเพื่อบำรุงรักษา กรุณาลองใหม่ในอีกสักครู่</p>';
             }
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
             $ul->appendChild('<li><span>{LNG_Maintenance Mode}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             // แสดงฟอร์ม
             $section->appendChild(createClass('Index\\Maintenance\\View')->render($language, $template));
             return $section->render();
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 2
0
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // รายการที่ต้องการ
         $index = \Index\Menuwrite\Model::getMenu(self::$request->get('id')->toInt());
         if ($index) {
             // สร้างหรือแก้ไข
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-modules">{LNG_Menus} &amp; {LNG_Web pages}</span></li>');
             $ul->appendChild('<li><a href="{BACKURL?module=pages&id=0}">{LNG_Menus}</a></li>');
             $ul->appendChild('<li><span>{LNG_' . (empty($index->id) ? 'Create' : 'Edit') . '}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             if ($index) {
                 // แสดงฟอร์ม
                 $section->appendChild(createClass('Index\\Menuwrite\\View')->render($index));
                 return $section->render();
             }
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 3
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // รายการที่ต้องการ
         $index = \Index\Mailwrite\Model::getIndex(self::$request->get('id')->toInt());
         // สร้างหรือแก้ไข
         $title = Language::get(empty($index->id) ? 'Create' : 'Edit');
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
         $ul->appendChild('<li><a href="{BACKURL?module=mailtemplate&id=0}">{LNG_Email template}</a></li>');
         $ul->appendChild('<li><span>' . $title . '</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $title . ' ' . $index->name . '</h1>'));
         if ($index) {
             // แสดงฟอร์ม
             $section->appendChild(createClass('Index\\Mailwrite\\View')->render($index));
             return $section->render();
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
 /**
  * action
  */
 public static function action()
 {
     $ret = array();
     // referer, session, admin
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             if (self::$request->post('action')->toString() === 'delete') {
                 $id = self::$request->post('action')->toInt();
                 $rs = Recordset::create(get_called_class());
                 $index = $rs->find($id);
                 if ($index) {
                     $index->delete();
                 }
                 // คืนค่า
                 $ret['delete_id'] = self::$request->post('src')->toString() . '_' . $id;
                 $ret['alert'] = Language::get('Deleted successfully');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 5
0
 /**
  * แสดงผล
  */
 public function render($login)
 {
     // send email form
     $form = Html::create('form', array('id' => 'write_frm', 'class' => 'setup_frm', 'action' => 'index.php/index/model/sendmail/save', 'onsubmit' => 'doFormSubmit', 'token' => true, 'ajax' => true));
     $fieldset = $form->add('fieldset', array('title' => '{LNG_Details of} {LNG_Email}'));
     // reciever
     $reciever = self::$request->get('to')->topic();
     $fieldset->add('text', array('id' => 'reciever', 'itemClass' => 'item', 'labelClass' => 'g-input icon-email-sent', 'label' => '{LNG_Reciever}', 'comment' => '{LNG_Recipient&#39;s Email Address Many can be found Each separated by, (comma).}', 'autofocus', 'value' => $reciever));
     // email_from
     $datas = array($login['email'] => $login['email']);
     if (Login::isAdmin() && empty($login['fb'])) {
         $datas[self::$cfg->noreply_email] = self::$cfg->noreply_email;
         foreach (\Index\Sendmail\Model::findAdmin(self::$request) as $item) {
             $datas[$item] = $item;
         }
     }
     $fieldset->add('select', array('id' => 'from', 'itemClass' => 'item', 'labelClass' => 'g-input icon-email', 'label' => '{LNG_Sender}', 'options' => $datas));
     // subject
     $fieldset->add('text', array('id' => 'subject', 'itemClass' => 'item', 'labelClass' => 'g-input icon-edit', 'label' => '{LNG_Subject}', 'comment' => '' . '{LNG_Please fill in} {LNG_Subject}'));
     // detail
     $fieldset->add('ckeditor', array('id' => 'detail', 'itemClass' => 'item', 'height' => 300, 'language' => Language::name(), 'toolbar' => 'Email', 'label' => '{LNG_Detail}', 'value' => Template::load('', '', 'mailtemplate')));
     $fieldset = $form->add('fieldset', array('class' => 'submit'));
     // submit
     $fieldset->add('submit', array('class' => 'button ok large', 'value' => '{LNG_Send message}'));
     return $form->render();
 }
Ejemplo n.º 6
0
 /**
  * form submit
  */
 public function save()
 {
     $ret = array();
     // referer, session, member
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // โหลด config
             $config = Config::load(ROOT_PATH . 'settings/config.php');
             $config->member_reserv = array();
             foreach (explode("\n", self::$request->post('member_reserv')->text()) as $item) {
                 $config->member_reserv[] = trim($item);
             }
             $config->wordrude = array();
             foreach (explode("\n", self::$request->post('wordrude')->text()) as $item) {
                 $config->wordrude[] = trim($item);
             }
             $config->wordrude_replace = self::$request->post('wordrude_replace', 'xxx')->toString();
             $config->counter_digit = max(4, self::$request->post('counter_digit')->toInt());
             // save config
             if (Config::save($config, ROOT_PATH . 'settings/config.php')) {
                 $ret['alert'] = Language::get('Saved successfully');
                 $ret['location'] = 'reload';
             } else {
                 $ret['alert'] = sprintf(Language::get('File %s cannot be created or is read-only.'), 'settings/config.php');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 7
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // ภาษาที่ต้องการ
         $language = self::$request->get('language', Language::name())->toString();
         if (preg_match('/^[a-z]{2,2}$/', $language)) {
             // intro detail
             $template = ROOT_PATH . DATA_FOLDER . 'intro.' . $language . '.php';
             if (is_file($template)) {
                 $template = trim(preg_replace('/<\\?php exit([\\(\\);])?\\?>/', '', file_get_contents($template)));
             } else {
                 $template = '<p style="padding: 20px; text-align: center; font-weight: bold;"><a href="index.php">Welcome<br>ยินดีต้อนรับ</a></p>';
             }
             // แสดงผล
             $section = Html::create('section');
             // breadcrumbs
             $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
             $ul = $breadcrumbs->add('ul');
             $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
             $ul->appendChild('<li><span>{LNG_Intro Page}</span></li>');
             $section->add('header', array('innerHTML' => '<h1 class="icon-write">' . $this->title() . '</h1>'));
             // แสดงฟอร์ม
             $section->appendChild(createClass('Index\\Intro\\View')->render($language, $template));
             return $section->render();
         }
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 8
0
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // โมดูลที่ต้องการติดตั้ง
         $module = $request->get('m')->filter('a-z');
         $widget = $request->get('w')->filter('a-z');
         $this->module = $module !== '' ? $module : $widget;
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         if ($module !== '') {
             $ul->appendChild('<li><span class="icon-modules">{LNG_Module}</span></li>');
             $type = 'module';
         } elseif ($widget !== '') {
             $ul->appendChild('<li><span class="icon-widgets">{LNG_Widgets}</span></li>');
             $type = 'widget';
         } else {
             // 404.html
             return \Index\Error\Controller::page404();
         }
         $ul->appendChild('<li><span>{LNG_Install}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-inbox">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Install\\View')->render($type, $this->module));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 9
0
 /**
  * รับค่าจาก 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);
 }
Ejemplo n.º 10
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-modules">{LNG_Menus} &amp; {LNG_Web pages}</span></li>');
         $ul->appendChild('<li><a href="{BACKURL?module=mods&id=0}">{LNG_installed module}</a></li>');
         $ul->appendChild('<li><span>{LNG_Create}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-new">' . $this->title() . '</h1>'));
         // owner
         $modules = array();
         foreach (Gcms::$install_owners as $owner => $item) {
             if (file_exists(ROOT_PATH . 'modules/' . $owner . '/controllers/admin/init.php')) {
                 $class = ucfirst($owner) . '\\Admin\\Init\\Controller';
                 if (method_exists($class, 'description')) {
                     // get module description
                     $description = $class::description();
                     if (!empty($description)) {
                         $modules[$owner] = $description . ' [' . $owner . ']';
                     }
                 }
             }
         }
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Addmodule\\View')->render($modules));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 11
0
 /**
  * ฟังก์ชั่นจัดการ debug อ่าน,ลบ
  */
 public function action()
 {
     // referer, session, admin
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] != 'demo' && empty($login['fb'])) {
             // action
             $action = self::$request->post('action')->toString();
             // file debug
             $debug = ROOT_PATH . DATA_FOLDER . 'logs/error_log.php';
             if (is_file($debug)) {
                 if ($action == 'get') {
                     // อ่าน debug
                     $t = self::$request->post('t')->toString();
                     foreach (file($debug) as $i => $row) {
                         if (preg_match('/^\\[([0-9\\-:\\s]+)\\][\\s]+([A-Z]+):[\\s]+(.*)/', trim($row), $match)) {
                             if ($match[1] > $t) {
                                 echo "{$match['1']}\t{$match['2']}\t{$match['3']}\n";
                             }
                         }
                     }
                 } elseif ($action == 'clear') {
                     // ลบไฟล์ debug
                     unlink($debug);
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // สมาชิก
     if ($login = Login::isMember()) {
         // id ที่ต้องการ ถ้าไม่มีใช้คนที่ login
         $id = self::$request->get('id', $login['id'])->toInt();
         // อ่านข้อมูลสมาชิก
         $user = \Index\Editprofile\Model::getUser($id);
         if ($user && ($login['status'] == 1 || $login['id'] == $user->id)) {
             $template = Template::create('', '', 'editprofile');
             $contents = array();
             foreach ($user as $key => $value) {
                 if ($key === 'provinceID' || $key === 'country' || $key === 'sex' || $key === 'status') {
                     // select
                     if ($key == 'provinceID') {
                         $source = Province::all();
                     } elseif ($key == 'country') {
                         $source = Country::all();
                     } elseif ($key == 'sex') {
                         $source = Language::get('SEXES');
                     } elseif ($key == 'status') {
                         $source = self::$cfg->member_status;
                     }
                     $datas = array();
                     foreach ($source as $k => $v) {
                         $sel = $k == $value ? ' selected' : '';
                         $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
                     }
                     $contents['/{' . strtoupper($key) . '}/'] = implode('', $datas);
                 } elseif ($key === 'admin_access' || $key === 'subscrib') {
                     $contents['/{' . strtoupper($key) . '}/'] = $value == 1 ? 'checked' : '';
                 } elseif ($key === 'icon') {
                     if (is_file(ROOT_PATH . self::$cfg->usericon_folder . $value)) {
                         $icon = WEB_URL . self::$cfg->usericon_folder . $value;
                     } else {
                         $icon = WEB_URL . 'skin/img/noicon.jpg';
                     }
                     $contents['/{ICON}/'] = $icon;
                 } else {
                     $contents['/{' . strtoupper($key) . '}/'] = $value;
                 }
             }
             $contents['/{ADMIN}/'] = Login::isAdmin() && $user->fb == 0 ? '' : 'readonly';
             $contents['/{HIDDEN}/'] = implode("\n", Form::get2Input());
             $contents['/{ACCEPT}/'] = Mime::getEccept(self::$cfg->user_icon_typies);
             $template->add($contents);
             Gcms::$view->setContents(array('/:type/' => implode(', ', self::$cfg->user_icon_typies)), false);
             return $template->render();
         } else {
             // 404.html
             return \Index\Error\Controller::page404();
         }
     } else {
         // 404.html
         return \Index\Error\Controller::page404();
     }
 }
Ejemplo n.º 13
0
 /**
  * รับค่าจาก action ของ table
  */
 public function action()
 {
     $ret = array();
     // referer, session, admin
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // ค่าที่ส่งมา
             $action = self::$request->post('action')->toString();
             $id = self::$request->post('id')->toInt();
             // Model
             $model = new \Kotchasan\Model();
             if ($action === 'published') {
                 // เผยแพร่
                 $index = $model->db()->first($model->getFullTableName('index'), $id);
                 if ($index) {
                     $published = $index->published == 1 ? 0 : 1;
                     $model->db()->update($model->getFullTableName('index'), $index->id, array('published' => $published));
                     // คืนค่า
                     $ret['elem'] = 'published_' . $index->id;
                     $lng = Language::get('PUBLISHEDS');
                     $ret['title'] = $lng[$published];
                     $ret['class'] = 'icon-published' . $published;
                 }
             } elseif ($action === 'delete') {
                 // ลบโมดูลและหน้าเพจ ไม่ลบข้อมูลของโมดูล
                 $query = $model->db()->createQuery()->select('id', 'module_id')->from('index')->where(array(array('index', 1), array('module_id', $model->db()->createQuery()->select('module_id')->from('index')->where(array('id', $id)))));
                 $count = 0;
                 foreach ($query->execute() as $field) {
                     $count++;
                     if ($field->id == $id) {
                         $model->db()->delete($model->getFullTableName('index'), $id);
                         $model->db()->delete($model->getFullTableName('index_detail'), $id);
                     }
                 }
                 // ลบโมดูล ถ้าไม่มีรายการในภาษาอื่น
                 if ($count < 2) {
                     $model->db()->delete($model->getFullTableName('modules'), $field->module_id);
                 }
                 // คืนค่า
                 $ret['delete_id'] = self::$request->post('src')->toString() . '_' . $id;
                 $ret['alert'] = Language::get('Deleted successfully');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 14
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if ($login = Login::isAdmin()) {
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-email">{LNG_Mailbox}</span></li>');
         $ul->appendChild('<li><span>{LNG_Email send}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-email-sent">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Sendmail\\View')->render($login));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 15
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-home">{LNG_Home}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-dashboard">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Dashboard\\View')->render());
         return $section->render();
     } else {
         // 404.html
         return \Index\Error\Controller::page404();
     }
 }
Ejemplo n.º 16
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><a class="icon-user" href="index.php?module=member">{LNG_Users}</a></li>');
         $ul->appendChild('<li><span>{LNG_Register}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-register">' . $this->title() . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Register\\View')->render());
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 17
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-tools">{LNG_Tools}</span></li>');
         $ul->appendChild('<li><span>{LNG_Language}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-language">' . $this->title() . '</h1>'));
         // แสดงตาราง
         $section->appendChild(createClass('Index\\Language\\View')->render());
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 18
0
 /**
  * แสดงผล
  */
 public function render(Request $request)
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-modules">{LNG_Menus} &amp; {LNG_Web pages}</span></li>');
         $ul->appendChild('<li><span>{LNG_installed module}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-modules">' . $this->title() . '</h1>'));
         // แสดงตาราง
         $section->appendChild(createClass('Index\\Mods\\View')->render());
         return $section->render();
     } else {
         // 404.html
         return \Index\Error\Controller::page404();
     }
 }
Ejemplo n.º 19
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
         $ul->appendChild('<li><span>{LNG_Other}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-config">' . $this->title() . '</h1>'));
         // โหลด config
         $config = Config::load(ROOT_PATH . 'settings/config.php');
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Other\\View')->render($config));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 20
0
 /**
  * บันทึก
  */
 public function save()
 {
     $ret = array();
     // referer, session, member
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $save = array('show_intro' => self::$request->post('show_intro')->toBoolean(), 'language' => self::$request->post('language')->toString(), 'detail' => self::$request->post('detail')->detail());
             if (!empty($save['language']) && preg_match('/^[a-z]{2,2}$/', $save['language'])) {
                 // save
                 $template = ROOT_PATH . DATA_FOLDER . 'intro.' . $save['language'] . '.php';
                 $f = @fopen($template, 'wb');
                 if ($f) {
                     fwrite($f, "<?php exit;?>\n" . $save['detail']);
                     fclose($f);
                     // โหลด config
                     $config = Config::load(ROOT_PATH . 'settings/config.php');
                     $config->show_intro = $save['show_intro'];
                     // save config
                     if (Config::save($config, ROOT_PATH . 'settings/config.php')) {
                         $ret['alert'] = Language::get('Saved successfully');
                         $ret['location'] = 'reload';
                     } else {
                         $ret['alert'] = sprintf(Language::get('File %s cannot be created or is read-only.'), 'settings/config.php');
                     }
                 } else {
                     $ret['alert'] = sprintf(Language::get('File %s cannot be created or is read-only.'), DATA_FOLDER . 'intro.' . $save['language'] . '.php');
                 }
             } else {
                 $ret['alert'] = Language::get('Unable to complete the transaction');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 21
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-tools">{LNG_Tools}</span></li>');
         $ul->appendChild('<li><span>' . $this->title() . '</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-world">' . $this->title() . '</h1>'));
         $div = $section->add('div', array('class' => 'setup_frm'));
         $div = $div->add('div', array('class' => 'item'));
         $div->appendChild('<div id="debug_layer"></div>');
         $div->appendChild('<div class="submit right"><a id="debug_clear" class="button large red">{LNG_Clear}</a></div>');
         $section->script('showDebug();');
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 22
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-tools">{LNG_Tools}</span></li>');
         $ul->appendChild('<li><span>{LNG_Database}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-database">' . $this->title() . '</h1>'));
         $div = $section->add('div', array('class' => 'setup_frm'));
         // แสดงฟอร์ม
         $view = new \Index\Database\View();
         $div->appendChild($view->export());
         $div->appendChild($view->import());
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 23
0
 /**
  * หน้าส่งอีเมล์
  * สมาชิกส่งจดหมายถึงสมาชิก และ แอดมิน
  *
  * @param Request $request
  * @return object
  */
 public function render(Request $request)
 {
     // สมาชิก
     if ($login = Login::isMember()) {
         // ค่าที่ส่งมา
         $to = strtolower($request->get('to')->filter('0-9a-zA-Z'));
         if (preg_match('/^[0-9]+$/', $to)) {
             $reciever = \Index\Sendmail\Model::getUser($to);
             $to = '';
             foreach ($reciever as $id => $item) {
                 $to_msg = empty($item['name']) ? $item['email'] : $item['name'];
                 $to = $id;
             }
         } elseif ($to == 'admin') {
             $to_msg = self::$cfg->member_status[1];
         } else {
             $to = '';
         }
         if ($to != '') {
             // antispam
             $antispam = new Antispam();
             // ข้อมูลส่งกลับ
             $index = (object) array('topic' => Language::replace('Send a message to the :name', array(':name' => $to_msg)), 'keywords' => self::$cfg->web_title, 'description' => self::$cfg->web_description, 'module' => 'sendmail');
             $template = Template::create('member', 'member', 'sendmail');
             $template->add(array('/{TOPIC}/' => $index->topic, '/{ANTISPAM}/' => $antispam->getId(), '/{ANTISPAMVAL}/' => Login::isAdmin() ? $antispam->getValue() : '', '/{RECIEVER}/' => $to_msg, '/{SENDER}/' => $login['email'], '/{RECIEVERID}/' => $to));
             $index->detail = $template->render();
             // breadcrumbs
             $index->canonical = WEB_URL . 'index.php?module=sendmail&to=' . $to;
             Gcms::$view->addBreadcrumb($index->canonical, $index->topic);
             return $index;
         }
     }
     // ไม่สามารถส่งอีเมล์ได้
     $message = Language::get('Unable to send e-mail, Because you can not send e-mail to yourself or can not find the email address of the recipient.');
     return createClass('Index\\PageNotFound\\Controller')->init($request, 'member', $message);
 }
Ejemplo n.º 24
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if (Login::isAdmin()) {
         // รายการที่ต้องการ
         $id = self::$request->get('id')->toString();
         $title = Language::get(empty($id) ? 'Create' : 'Edit');
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
         $ul->appendChild('<li><a href="{BACKURL?module=languages&id=0}">{LNG_Language}</a></li>');
         $ul->appendChild('<li><span>' . $title . '</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-language">' . $title . ' {LNG_Language} ' . $id . '</h1>'));
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Languageadd\\View')->render($id));
         return $section->render();
     } else {
         // 404.html
         return \Index\Error\Controller::page404();
     }
 }
Ejemplo n.º 25
0
 /**
  * แสดงผล
  */
 public function render()
 {
     // แอดมิน
     if ($login = Login::isAdmin()) {
         // โหลด config
         $config = Config::load(ROOT_PATH . 'settings/config.php');
         // path ของ skin
         $dir = ROOT_PATH . 'skin';
         // action
         $action = self::$request->get('action')->toString();
         if (!empty($action)) {
             if ($login['email'] == 'demo' || !empty($login['fb'])) {
                 $message = '<aside class=error>{LNG_Unable to complete the transaction}</aside>';
             } else {
                 $theme = preg_replace('/[\\/\\\\]/ui', '', self::$request->get('theme')->text());
                 if (is_dir($dir . "/{$theme}")) {
                     if ($action == 'use') {
                         // skin ที่กำหนด
                         $config->skin = $theme;
                         unset($_SESSION['skin']);
                         // บันทึก config.php
                         if (Config::save($config, ROOT_PATH . 'settings/config.php')) {
                             self::$request->setSession('my_skin', $config->skin);
                             $message = '<aside class=message>{LNG_Select a new template successfully}</aside>';
                         } else {
                             $message = '<aside class=error>' . sprintf(Language::get('File %s cannot be created or is read-only.'), 'settings/config.php') . '</aside>';
                         }
                     } elseif ($action == 'delete') {
                         // ลบ skin
                         File::removeDirectory($dir . '/' . $theme . '/');
                         $message = '<aside class=message>{LNG_Successfully remove template files}</aside>';
                     }
                 }
             }
         }
         // แสดงผล
         $section = Html::create('section');
         // breadcrumbs
         $breadcrumbs = $section->add('div', array('class' => 'breadcrumbs'));
         $ul = $breadcrumbs->add('ul');
         $ul->appendChild('<li><span class="icon-settings">{LNG_Site settings}</span></li>');
         $ul->appendChild('<li><span>{LNG_Template}</span></li>');
         $section->add('header', array('innerHTML' => '<h1 class="icon-template">' . $this->title() . '</h1>'));
         if (!empty($message)) {
             $section->appendChild($message);
         }
         // อ่าน theme ทั้งหมด
         $themes = array();
         $f = opendir($dir);
         while (false !== ($text = readdir($f))) {
             if ($text !== $config->skin && $text !== "." && $text !== "..") {
                 if (is_dir($dir . "/{$text}") && is_file($dir . "/{$text}/style.css")) {
                     $themes[] = $text;
                 }
             }
         }
         closedir($f);
         // แสดงฟอร์ม
         $section->appendChild(createClass('Index\\Template\\View')->render($dir, $config, $themes));
         return $section->render();
     }
     // 404.html
     return \Index\Error\Controller::page404();
 }
Ejemplo n.º 26
0
 /**
  * โหลดรายการเมนูทั้งหมด.
  *
  * @return array รายการเมนูทั้งหมด
  */
 public static function getMenus()
 {
     // menu section
     self::$menus['sections']['home'] = array('h', '<a href="index.php?module=dashboard" accesskey=h title="{LNG_Home}"><span>{LNG_Home}</span></a>');
     self::$menus['sections']['settings'] = array('1', '{LNG_Site settings}');
     self::$menus['sections']['index'] = array('2', '{LNG_Menus} &amp; {LNG_Web pages}');
     self::$menus['sections']['modules'] = array('3', '{LNG_Modules}');
     self::$menus['sections']['widgets'] = array('4', '{LNG_Widgets}');
     self::$menus['sections']['users'] = array('5', '{LNG_Users}');
     self::$menus['sections']['email'] = array('6', '{LNG_Mailbox}');
     self::$menus['sections']['tools'] = array('7', '{LNG_Tools}');
     // settings
     self::$menus['settings']['system'] = '<a href="index.php?module=system"><span>{LNG_General}</span></a>';
     self::$menus['settings']['mailserver'] = '<a href="index.php?module=mailserver"><span>{LNG_Email settings}</span></a>';
     self::$menus['settings']['mailtemplate'] = '<a href="index.php?module=mailtemplate"><span>{LNG_Email template}</span></a>';
     self::$menus['settings']['template'] = '<a href="index.php?module=template"><span>{LNG_Template}</span></a>';
     self::$menus['settings']['skin'] = '<a href="index.php?module=skin"><span>{LNG_Template settings}</span></a>';
     self::$menus['settings']['maintenance'] = '<a href="index.php?module=maintenance"><span>{LNG_Maintenance Mode}</span></a>';
     self::$menus['settings']['intro'] = '<a href="index.php?module=intro"><span>{LNG_Intro Page}</span></a>';
     self::$menus['settings']['languages'] = '<a href="index.php?module=languages"><span>{LNG_Language}</span></a>';
     self::$menus['settings']['other'] = '<a href="index.php?module=other"><span>{LNG_Other}</span></a>';
     self::$menus['settings']['meta'] = '<a href="index.php?module=meta"><span>{LNG_SEO &amp; Social}</span></a>';
     // email
     self::$menus['email']['sendmail'] = '<a href="index.php?module=sendmail"><span>{LNG_Email send}</span></a>';
     // เมนู
     self::$menus['index']['pages'] = '<a href="index.php?module=pages"><span>{LNG_Web pages}</span></a>';
     self::$menus['index']['insmod'] = '<a href="index.php?module=mods"><span>{LNG_installed module}</span></a>';
     self::$menus['index']['menu'] = '<a href="index.php?module=menus"><span>{LNG_Menus}</span></a>';
     // เมนูสมาชิก
     self::$menus['users']['memberstatus'] = '<a href="index.php?module=memberstatus"><span>{LNG_Member status}</span></a>';
     self::$menus['users']['member'] = '<a href="index.php?module=member"><span>{LNG_Member List}</span></a>';
     self::$menus['users']['register'] = '<a href="index.php?module=register"><span>{LNG_Register}</span></a>';
     // tools
     self::$menus['tools']['install'] = array();
     self::$menus['tools']['database'] = '<a href="index.php?module=database"><span>{LNG_Database}</span></a>';
     self::$menus['tools']['language'] = '<a href="index.php?module=language"><span>{LNG_Language}</span></a>';
     self::$menus['tools']['debug'] = '<a href="index.php?module=debug"><span>{LNG_Debug tool}</span></a>';
     self::$menus['modules'] = array();
     // โมดูลที่ติดตั้งแล้ว
     foreach (Gcms::$install_modules as $item) {
         // ตรวจสอบไฟล์ config
         if (is_file(ROOT_PATH . "modules/{$item['owner']}/controllers/settings.php")) {
             self::$menus['modules'][$item['module']]['config'] = '<a href="index.php?module=' . $item['owner'] . '-settings&amp;id=' . $item['id'] . '"><span>{LNG_Config}</span></a>';
         }
         // ตรวจสอบไฟล์ category
         if (is_file(ROOT_PATH . "modules/{$item['owner']}/controllers/category.php")) {
             self::$menus['modules'][$item['module']]['category'] = '<a href="index.php?module=' . $item['owner'] . '-category&amp;id=' . $item['id'] . '"><span>{LNG_Category}</span></a>';
         }
         // ตรวจสอบไฟล์ setup
         if (is_file(ROOT_PATH . "modules/{$item['owner']}/controllers/setup.php")) {
             self::$menus['modules'][$item['module']]['setup'] = '<a href="index.php?module=' . $item['owner'] . '-setup&amp;id=' . $item['id'] . '"><span>{LNG_Contents}</span></a>';
         }
     }
     if (!Login::isAdmin()) {
         unset(self::$menus['sections']['settings']);
         unset(self::$menus['sections']['index']);
         unset(self::$menus['sections']['menus']);
         unset(self::$menus['sections']['widgets']);
         unset(self::$menus['sections']['users']);
         unset(self::$menus['sections']['tools']);
     }
     if (sizeof(self::$menus['modules']) == 0) {
         unset(self::$menus['sections']['modules']);
     }
     if (isset(self::$menus['widgets']) && sizeof(self::$menus['widgets']) == 0) {
         unset(self::$menus['sections']['widgets']);
     }
     if (sizeof(self::$menus['tools']['install']) == 0) {
         unset(self::$menus['tools']['install']);
     }
 }
 /**
  * รับค่าจาก action
  */
 public function action()
 {
     $ret = array();
     // referer, session, member
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // โหลด config
             $config = Config::load(ROOT_PATH . 'settings/config.php');
             // รับค่าจากการ POST
             $action = self::$request->post('action')->toString();
             // do not saved
             $save = false;
             // default
             if (!isset($config->member_status[0])) {
                 $config->member_status[0] = 'สมาชิก';
                 $save = true;
             }
             if (!isset($config->member_status[1])) {
                 $config->member_status[1] = 'ผู้ดูแลระบบ';
                 $save = true;
             }
             if (!isset($config->color_status[0])) {
                 $config->color_status[0] = '#006600';
                 $save = true;
             }
             if (!isset($config->color_status[1])) {
                 $config->color_status[1] = '#FF0000';
                 $save = true;
             }
             if ($action === 'config_status_add') {
                 // เพิ่มสถานะสมาชิกใหม่
                 $config->member_status[] = Language::get('click to edit');
                 $config->color_status[] = '#000000';
                 // id ของสถานะใหม่
                 $i = sizeof($config->member_status) - 1;
                 // ข้อมูลใหม่
                 $row = '<dd id="config_status_' . $i . '">';
                 $row .= '<span class="icon-delete" id="config_status_delete_' . $i . '" title="{LNG_Delete}"></span>';
                 $row .= '<span id="config_status_color_' . $i . '" title="' . $config->color_status[$i] . '"></span>';
                 $row .= '<span id="config_status_name_' . $i . '" title="' . $config->member_status[$i] . '">' . htmlspecialchars($config->member_status[$i]) . '</span>';
                 $row .= '</dd>';
                 // คืนค่าข้อมูลเข้ารหัส
                 $ret['data'] = $row;
                 $ret['newId'] = "config_status_{$i}";
                 $save = true;
             } elseif (preg_match('/^config_status_delete_([0-9]+)$/', $action, $match)) {
                 // ลบ
                 $save1 = array();
                 $save2 = array();
                 // ลบสถานะและสี
                 for ($i = 0; $i < sizeof($config->member_status); $i++) {
                     if ($i < 2 || $i != $match[1]) {
                         $save1[] = $config->member_status[$i];
                         $save2[] = $config->color_status[$i];
                     }
                 }
                 $config->member_status = $save1;
                 $config->color_status = $save2;
                 // รายการที่ลบ
                 $ret['del'] = str_replace('delete_', '', $action);
                 $save = true;
             } elseif (preg_match('/^config_status_(name|color)_([0-9]+)$/', $action, $match)) {
                 // แก้ไขชื่อสถานะหรือสี
                 $value = self::$request->post('value')->text();
                 $match[2] = (int) $match[2];
                 if ($value == '' && $match[1] == 'name') {
                     $value = $config->member_status[$match[2]];
                 } elseif ($value == '' && $match[1] == 'color') {
                     $value = $config->color_status[$match[2]];
                 } elseif ($match[1] == 'name') {
                     $config->member_status[$match[2]] = $value;
                     $save = true;
                 } else {
                     $config->color_status[$match[2]] = $value;
                     $save = true;
                 }
                 // ส่งข้อมูลใหม่ไปแสดงผล
                 $ret['edit'] = $value;
                 $ret['editId'] = $action;
             }
             // save config
             if ($save && !Config::save($config, ROOT_PATH . 'settings/config.php')) {
                 $ret['alert'] = sprintf(Language::get('File %s cannot be created or is read-only.'), 'settings/config.php');
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     echo json_encode($ret);
 }
Ejemplo n.º 28
0
 /**
  * form submit
  */
 public function save()
 {
     $ret = array();
     // referer, session, member
     if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo') {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // โหลด config
             $config = Config::load(ROOT_PATH . 'settings/config.php');
             // รับค่าจากการ POST
             $post = array('language_name' => self::$request->post('language_name')->text(), 'copy' => self::$request->post('lang_copy')->text(), 'language' => self::$request->post('language')->text());
             // ตรวจสอบค่าที่ส่งมา
             $input = false;
             if (preg_match('/^[a-z]{2,2}$/', $post['language_name'])) {
                 $ret['ret_language_name'] = '';
             } else {
                 $input = !$input ? 'language_name' : $input;
             }
             if (!$input) {
                 if (empty($post['language'])) {
                     // สร้างภาษาใหม่
                     if (!@copy(ROOT_PATH . 'language/' . $post['copy'] . '.php', ROOT_PATH . 'language/' . $post['language_name'] . '.php')) {
                         // error copy file
                         $ret['alert'] = sprintf(Language::get('Directory %s cannot be created or is read-only.'), 'language/');
                     } else {
                         @copy(ROOT_PATH . 'language/' . $post['copy'] . '.js', ROOT_PATH . 'language/' . $post['language_name'] . '.js');
                         @copy(ROOT_PATH . 'language/' . $post['copy'] . '.gif', ROOT_PATH . 'language/' . $post['language_name'] . '.gif');
                         $config->languages[] = $post['language_name'];
                     }
                 } elseif ($post['language_name'] != $post['language']) {
                     // เปลี่ยนชื่อภาษา
                     rename(ROOT_PATH . 'language/' . $post['language'] . '.php', ROOT_PATH . 'language/' . $post['language_name'] . '.php');
                     rename(ROOT_PATH . 'language/' . $post['language'] . '.js', ROOT_PATH . 'language/' . $post['language_name'] . '.js');
                     rename(ROOT_PATH . 'language/' . $post['language'] . '.gif', ROOT_PATH . 'language/' . $post['language_name'] . '.gif');
                     foreach ($config->languages as $i => $item) {
                         if ($item == $post['language']) {
                             $config->languages[$i] = $post['language_name'];
                         }
                     }
                 }
                 // ไอคอนอัปโหลด
                 foreach (self::$request->getUploadedFiles() as $item => $file) {
                     if ($file->hasUploadFile()) {
                         // ตรวจสอบไฟล์อัปโหลด
                         if (!$file->validFileExt(array('gif'))) {
                             $ret['alert'] = Language::get('The type of file is invalid');
                             $input = !$input ? $item : $input;
                         } else {
                             try {
                                 $file->moveTo(ROOT_PATH . 'language/' . $post['language_name'] . '.gif');
                             } catch (\Exception $exc) {
                                 // ไม่สามารถอัปโหลดได้
                                 $ret['ret_' . $item] = Language::get($exc->getMessage());
                                 $input = !$input ? $item : $input;
                             }
                         }
                     }
                 }
                 if (!$input) {
                     // save config
                     if (Config::save($config, ROOT_PATH . 'settings/config.php')) {
                         $ret['alert'] = Language::get('Saved successfully');
                         $ret['location'] = self::$request->getUri()->postBack('index.php', array('module' => 'languages'));
                     } else {
                         $ret['alert'] = sprintf(Language::get('File %s cannot be created or is read-only.'), 'settings/config.php');
                     }
                 }
             }
             if ($input) {
                 // คืนค่า input ที่ error
                 $ret['input'] = $input;
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่า json
     echo json_encode($ret);
 }
Ejemplo n.º 29
0
 /**
  * รับค่าจาก action
  */
 public function action(Request $request)
 {
     if ($request->initSession() && $request->isReferer() && ($login = Login::isAdmin())) {
         if ($login['email'] == 'demo' || !empty($login['fb'])) {
             echo Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $action = $request->post('action')->toString();
             // id ที่ส่งมา
             if (preg_match_all('/,?([0-9]+),?/', $request->post('id')->toString(), $match)) {
                 // Model
                 $model = new \Kotchasan\Model();
                 // ตาราง user
                 $user_table = $model->getFullTableName('user');
                 if ($action === 'delete') {
                     // ลบไอคอนสมาชิก
                     $query = $model->db()->createQuery()->select('icon')->from('user')->where(array(array('id', $match[1]), array('id', '!=', 1), array('icon', '!=', '')));
                     foreach ($query->toArray()->execute() as $item) {
                         @unlink(ROOT_PATH . self::$cfg->usericon_folder . $item['icon']);
                     }
                     // ลบสมาชิก
                     $model->db()->delete($user_table, array(array('id', $match[1]), array('id', '!=', 1)), 0);
                 } elseif ($action === 'accept') {
                     // ยอมรับสมาชิกที่เลือก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('fb', '0')), array('activatecode' => ''));
                 } elseif ($action === 'ban' || $action === 'unban') {
                     // ระงับ/ยกเลิก การใช้งานสมาชิก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('id', '!=', 1)), array('ban' => $action == 'ban' ? 1 : 0));
                 } elseif ($action === 'activate' || $action === 'sendpassword') {
                     // ส่งอีเมล์ยืนยันสมาชิก
                     $query = $model->db()->createQuery()->select('id', 'email', 'activatecode')->from('user')->where(array(array('id', $match[1]), array('id', '!=', 1), array('fb', '0')));
                     $msgs = array();
                     foreach ($query->toArray()->execute() as $item) {
                         // รหัสผ่านใหม่
                         $password = Text::rndname(6);
                         // ข้อมูลอีเมล์
                         $replace = array('/%PASSWORD%/' => $password, '/%EMAIL%/' => $item['email']);
                         $save = array('password' => md5($password . $item['email']));
                         if ($action === 'activate' || !empty($item['activatecode'])) {
                             // activate หรือ ยังไม่ได้ activate
                             $save['activatecode'] = empty($item['activatecode']) ? Text::rndname(32) : $item['activatecode'];
                             $replace['/%ID%/'] = $save['activatecode'];
                             // send mail
                             $err = Email::send(1, 'member', $replace, $item['email']);
                         } else {
                             // send mail
                             $err = Email::send(3, 'member', $replace, $item['email']);
                         }
                         $msgs = array();
                         if (empty($err)) {
                             // อัปเดทรหัสผ่านใหม่
                             $model->db()->update($user_table, $item['id'], $save);
                         } else {
                             $msgs[] = $err;
                         }
                         if (empty($msgs)) {
                             // ส่งอีเมล์ สำเร็จ
                             echo Language::get('Your message was sent successfully');
                         } else {
                             // มีข้อผิดพลาด
                             echo implode("\n", $msgs);
                         }
                     }
                 } elseif ($request->post('module')->toString() === 'status') {
                     // เปลี่ยนสถานะสมาชิก
                     $model->db()->update($user_table, array(array('id', $match[1]), array('id', '!=', 1), array('fb', '0')), array('status' => (int) $action));
                 }
             }
         }
     }
 }
 /**
  * บันทึก
  */
 public function save(Request $request)
 {
     $ret = array();
     // referer, session, member
     if ($request->initSession() && $request->isReferer() && ($login = Login::isMember())) {
         if ($login['email'] == 'demo' || !empty($login['fb'])) {
             $ret['alert'] = Language::get('Unable to complete the transaction');
         } else {
             // รับค่าจากการ POST
             $save = array('email' => $request->post('register_email')->url(), 'displayname' => $request->post('register_displayname')->topic(), 'sex' => $request->post('register_sex')->topic(), 'website' => str_replace(array('http://', 'https://', 'ftp://'), array('', '', ''), $request->post('register_website')->url()), 'pname' => $request->post('register_pname')->topic(), 'fname' => $request->post('register_fname')->topic(), 'lname' => $request->post('register_lname')->topic(), 'company' => $request->post('register_company')->topic(), 'phone1' => $request->post('register_phone1')->number(), 'phone2' => $request->post('register_phone2')->number(), 'subscrib' => $request->post('register_subscrib')->toBoolean(), 'address1' => $request->post('register_address1')->topic(), 'address2' => $request->post('register_address2')->topic(), 'provinceID' => $request->post('register_provinceID')->number(), 'province' => $request->post('register_province')->topic(), 'zipcode' => $request->post('register_zipcode')->number(), 'country' => $request->post('register_country')->topic(), 'status' => $request->post('register_status')->toInt(), 'birthday' => $request->post('register_birthday')->date(), 'admin_access' => $request->post('register_admin_access')->toBoolean());
             // ชื่อตาราง user
             $user_table = $this->getFullTableName('user');
             // database connection
             $db = $this->db();
             // ตรวจสอบค่าที่ส่งมา
             $id = $request->post('register_id')->toInt();
             if ($id == 0) {
                 // ใหม่
                 $user = (object) array('id' => 0, 'email' => '', 'fb' => 0);
             } else {
                 // แก้ไข
                 $user = $db->first($user_table, $id);
             }
             if (!$user) {
                 // ไม่พบสมาชิกที่แก้ไข
                 $ret['alert'] = Language::get('not a registered user');
             } else {
                 $isAdmin = Login::isAdmin();
                 // ไม่ใช่แอดมิน ใช้อีเมล์เดิมจากฐานข้อมูล
                 if (!$isAdmin && $user->id > 0) {
                     $save['email'] = $user->email;
                 }
                 // ตรวจสอบค่าที่ส่งมา
                 $input = false;
                 $requirePassword = false;
                 // อีเมล์
                 if (empty($save['email'])) {
                     $ret['ret_register_email'] = 'this';
                     $input = !$input ? 'register_email' : $input;
                 } else {
                     // ตรวจสอบอีเมล์ซ้ำ
                     $search = $db->first($user_table, array('email', $save['email']));
                     if ($search !== false && $user->id != $search->id) {
                         $ret['ret_register_email'] = str_replace(':name', Language::get('Email'), Language::get('This :name is already registered'));
                         $input = !$input ? 'register_email' : $input;
                     } else {
                         $requirePassword = $user->email !== $save['email'];
                         $ret['ret_register_email'] = '';
                     }
                 }
                 // ชื่อเรียก
                 if (!empty($save['displayname'])) {
                     // ตรวจสอบ ชื่อเรียก
                     $search = $db->first($user_table, array('displayname', $save['displayname']));
                     if ($search !== false && $user->id != $search->id) {
                         $ret['ret_register_displayname'] = str_replace(':name', Language::get('Name'), Language::get('This :name is already registered'));
                         $input = !$input ? 'register_displayname' : $input;
                     } else {
                         $ret['ret_register_displayname'] = '';
                     }
                 }
                 // โทรศัพท์
                 if (!empty($save['phone1'])) {
                     if (!preg_match('/[0-9]{9,10}/', $save['phone1'])) {
                         $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('Invalid :name'));
                         $input = !$input ? 'register_phone1' : $input;
                     } else {
                         // ตรวจสอบโทรศัพท์
                         $search = $db->first($user_table, array('phone1', $save['phone1']));
                         if ($search !== false && $user->id != $search->id) {
                             $ret['ret_register_phone1'] = str_replace(':name', Language::get('phone number'), Language::get('This :name is already registered'));
                             $input = !$input ? 'register_phone1' : $input;
                         } else {
                             $ret['ret_register_phone1'] = '';
                         }
                     }
                 }
                 // password
                 $password = $request->post('register_password')->topic();
                 $repassword = $request->post('register_repassword')->topic();
                 if (!empty($password) || !empty($repassword)) {
                     if (mb_strlen($password) < 4) {
                         // รหัสผ่านต้องไม่น้อยกว่า 4 ตัวอักษร
                         $ret['ret_register_password'] = '******';
                         $input = !$input ? 'register_password' : $input;
                     } elseif ($repassword != $password) {
                         // ถ้าต้องการเปลี่ยนรหัสผ่าน กรุณากรอกรหัสผ่านสองช่องให้ตรงกัน
                         $ret['ret_register_repassword'] = '******';
                         $input = !$input ? 'register_repassword' : $input;
                     } else {
                         $ret['ret_register_password'] = '';
                         $ret['ret_register_repassword'] = '';
                         $save['password'] = md5($password . $save['email']);
                         $requirePassword = false;
                     }
                 }
                 // มีการเปลี่ยน email ต้องการรหัสผ่าน
                 if (!$input && $requirePassword) {
                     $ret['ret_register_password'] = '******';
                     $input = !$input ? 'register_password' : $input;
                 }
                 // อัปโหลดไฟล์
                 foreach ($request->getUploadedFiles() as $item => $file) {
                     if ($file->hasUploadFile()) {
                         if (!File::makeDirectory(ROOT_PATH . self::$cfg->usericon_folder)) {
                             // ไดเรคทอรี่ไม่สามารถสร้างได้
                             $ret['ret_' . $item] = sprintf(Language::get('Directory %s cannot be created or is read-only.'), self::$cfg->usericon_folder);
                             $input = !$input ? $item : $input;
                         } else {
                             if (!empty($user->icon)) {
                                 // ลบไฟล์เดิม
                                 @unlink(ROOT_PATH . self::$cfg->usericon_folder . $user->icon);
                             }
                             try {
                                 // อัปโหลด thumbnail
                                 $save['icon'] = $user->id . '.jpg';
                                 $file->cropImage(self::$cfg->user_icon_typies, ROOT_PATH . self::$cfg->usericon_folder . $save['icon'], self::$cfg->user_icon_w, self::$cfg->user_icon_h);
                             } catch (\Exception $exc) {
                                 // ไม่สามารถอัปโหลดได้
                                 $ret['ret_' . $item] = Language::get($exc->getMessage());
                                 $input = !$input ? $item : $input;
                             }
                         }
                     }
                 }
                 if (!$input) {
                     // ไม่ใช่แอดมิน
                     if (!$isAdmin) {
                         unset($save['status']);
                         unset($save['point']);
                         unset($save['admin_access']);
                     }
                     // social ห้ามแก้ไข
                     if (!empty($user->fb)) {
                         unset($save['email']);
                         unset($save['password']);
                     }
                     if ($login['id'] == $id || $id == 1) {
                         unset($save['admin_access']);
                     }
                     // บันทึก
                     if ($id == 0) {
                         // ใหม่
                         $id = $db->insert($user_table, $save);
                         // ไปหน้ารายการสมาชิก
                         $ret['location'] = $request->getUri()->postBack('index.php', array('module' => 'member', 'id' => null, 'page' => null));
                     } else {
                         // แก้ไข
                         $db->update($user_table, $id, $save);
                         if ($login['id'] == $id) {
                             // ตัวเอง
                             if (isset($save['password'])) {
                                 if (isset($save['email'])) {
                                     $_SESSION['login']['email'] = $save['email'];
                                 }
                                 $_SESSION['login']['password'] = $password;
                             }
                             // reload หน้าเว็บ
                             $ret['location'] = 'reload';
                         } else {
                             // กลับไปหน้าก่อนหน้า
                             $ret['location'] = $request->getUri()->postBack('index.php', array('id' => null));
                         }
                     }
                     // คืนค่า
                     $ret['alert'] = Language::get('Saved successfully');
                 } else {
                     // error
                     $ret['input'] = $input;
                 }
             }
         }
     } else {
         $ret['alert'] = Language::get('Unable to complete the transaction');
     }
     // คืนค่าเป็น JSON
     if (!empty($ret)) {
         echo json_encode($ret);
     }
 }