/**
  * แสดงผล
  *
  * @return string
  */
 public function render(Request $request)
 {
     // อ่านข้อมูลสมาชิก
     $model = new Model();
     $user = $model->db()->createQuery()->from('user')->where(array('id', (int) $_SESSION['login']['id']))->first();
     $template = Template::create('member', 'member', 'profile');
     $contents = array('/<NEWREGISTER>(.*)<\\/NEWREGISTER>/isu' => $request->request('action')->toString() === 'newregister' ? '\\1' : '', '/<IDCARD>(.*)<\\/IDCARD>/isu' => empty(self::$cfg->member_idcard) ? '' : '\\1', '/{ACCEPT}/' => Mime::getEccept(self::$cfg->user_icon_typies));
     // ข้อมูลฟอร์ม
     foreach ($user as $key => $value) {
         if ($key == 'sex') {
             $datas = array();
             foreach (Language::get('SEXES') as $k => $v) {
                 $sel = $k == $value ? ' selected' : '';
                 $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
             }
             $contents['/{SEX}/'] = implode('', $datas);
         } elseif ($key === 'subscrib') {
             $contents['/{SUBSCRIB}/'] = $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;
         }
     }
     $template->add($contents);
     // after render
     Gcms::$view->setContents(array('/:type/' => empty(self::$cfg->user_icon_typies) ? 'jpg' : implode(', ', self::$cfg->user_icon_typies)), false);
     return $template->render();
 }
 /**
  * แสดงผล
  *
  * @return string
  */
 public function render()
 {
     // อ่านข้อมูลสมาชิก
     $rs = Recordset::create('Index\\User\\Model');
     $user = $rs->where((int) $_SESSION['login']['id'])->first('id');
     $template = Template::create('member', 'member', 'password');
     $contents = array('/{ACCEPT}/' => Mime::getEccept(self::$cfg->user_icon_typies), '/{USER_ICON_TYPIES}/' => sprintf(Language::get('Upload a picture of %s resize automatically'), empty(self::$cfg->user_icon_typies) ? 'jpg' : implode(', ', self::$cfg->user_icon_typies)));
     // ข้อมูลฟอร์ม
     foreach ($user as $key => $value) {
         if ($key == 'sex') {
             $source = Language::get('SEXES');
             $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 === '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;
         }
     }
     $template->add($contents);
     return $template->render();
 }
 /**
  * แสดงผล
  */
 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();
     }
 }
Example #4
0
 /**
  * ฟังก์ชั่นสร้าง Form Element
  *
  * @param string $tag
  * @param array $param property ของ Input
  * id, name, type property ต่างๆของinput
  * label : ข้อความแสดงใน label ของ input
  * labelClass : class ของ label
  * comment : ถ้ากำหนดจะแสดงคำอธิบายของ input
  * ถ้าไม่กำหนดทั้ง label และ labelClass จะเป็นการสร้าง input อย่างเดียว
  * @param string $options ตัวเลือก options ของ select
  * array('name1' => 'value1', 'name2' => 'value2', ....)
  */
 public function render()
 {
     $prop = array();
     $event = array();
     foreach ($this->attributes as $k => $v) {
         switch ($k) {
             case 'itemClass':
             case 'itemId':
             case 'labelClass':
             case 'label':
             case 'comment':
             case 'unit':
             case 'value':
             case 'dataPreview':
             case 'previewSrc':
             case 'accept':
             case 'options':
             case 'optgroup':
             case 'multiple':
             case 'validator':
             case 'antispamid':
             case 'text':
             case 'validator':
                 ${$k} = $v;
                 break;
             case 'result':
                 $prop[$k] = 'data-' . $k . '="' . $v . '"';
                 break;
             case 'title':
                 $prop['title'] = 'title="' . strip_tags($v) . '"';
                 break;
             default:
                 if (is_int($k)) {
                     $prop[$v] = $v;
                 } elseif ($v === true) {
                     $prop[$k] = $k;
                 } elseif ($v === false) {
                     continue;
                 } elseif (preg_match('/^on([a-z]+)/', $k, $match)) {
                     $event[$match[1]] = $v;
                 } else {
                     $prop[$k] = $k . '="' . $v . '"';
                     ${$k} = $v;
                 }
                 break;
         }
     }
     if (isset($id) && empty($name)) {
         $name = $id;
         $prop['name'] = 'name="' . $name . '"';
     }
     if (isset(Html::$form)) {
         if (isset($id) && Html::$form->gform) {
             if (isset($validator)) {
                 $js = array();
                 $js[] = '"' . $id . '"';
                 $js[] = '"' . $validator[0] . '"';
                 $js[] = $validator[1];
                 if (isset($validator[2])) {
                     $js[] = '"' . $validator[2] . '"';
                     $js[] = empty($validator[3]) || $validator[3] === null ? 'null' : '"' . $validator[3] . '"';
                     $js[] = '"' . Html::$form->attributes['id'] . '"';
                 }
                 $this->javascript[] = 'new GValidator(' . implode(', ', $js) . ');';
                 unset($validator);
             }
             foreach ($event as $on => $func) {
                 $this->javascript[] = '$G("' . $id . '").addEvent("' . $on . '", ' . $func . ');';
             }
         } elseif (!Html::$form->gform) {
             foreach ($event as $on => $func) {
                 $prop['on' . $on] = 'on' . $on . '="' . $func . '()"';
             }
         }
     }
     if ($this->tag == 'select') {
         unset($prop['type']);
         if (isset($multiple)) {
             $value = isset($value) ? $value : array();
         } else {
             $value = isset($value) ? $value : null;
         }
         if (isset($options)) {
             $datas = array();
             foreach ($options as $k => $v) {
                 if (is_array($value)) {
                     $sel = in_array($k, $value) ? ' selected' : '';
                 } else {
                     $sel = $value == $k ? ' selected' : '';
                 }
                 $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
             }
             $value = implode('', $datas);
         } elseif (isset($optgroup)) {
             $datas = array();
             foreach ($optgroup as $group_label => $options) {
                 $datas[] = '<optgroup label="' . $group_label . '">';
                 foreach ($options as $k => $v) {
                     if (is_array($value)) {
                         $sel = in_array($k, $value) ? ' selected' : '';
                     } else {
                         $sel = $value == $k ? ' selected' : '';
                     }
                     $datas[] = '<option value="' . $k . '"' . $sel . '>' . $v . '</option>';
                 }
                 $datas[] = '</optgroup>';
             }
             $value = implode('', $datas);
         }
     } elseif (isset($value)) {
         if ($this->tag === 'textarea') {
             $value = str_replace(array('{', '}', '&amp;'), array('&#x007B;', '&#x007D;', '&'), htmlspecialchars($value));
         } else {
             $prop['value'] = 'value="' . str_replace('&amp;', '&', htmlspecialchars($value)) . '"';
         }
     }
     if (empty($prop['title']) && !empty($comment)) {
         $prop['title'] = 'title="' . strip_tags($comment) . '"';
     }
     if (isset($dataPreview)) {
         $prop['data-preview'] = 'data-preview="' . $dataPreview . '"';
     }
     if (isset($accept) && is_array($accept)) {
         $prop['accept'] = 'accept="' . Mime::getEccept($accept) . '"';
     }
     if (isset($multiple)) {
         $prop['multiple'] = 'multiple';
     }
     $prop = implode(' ', $prop);
     if ($this->tag == 'input') {
         $element = '<' . $this->tag . ' ' . $prop . '>';
     } elseif (isset($value)) {
         $element = '<' . $this->tag . ' ' . $prop . '>' . $value . '</' . $this->tag . '>';
     } else {
         $element = '<' . $this->tag . ' ' . $prop . '></' . $this->tag . '>';
     }
     if (!empty($antispamid)) {
         $element = Antispam::createImage($antispamid, true) . $element;
     }
     if (empty($itemClass)) {
         $input = empty($comment) ? '' : '<div class="item"' . (empty($itemId) ? '' : ' id="' . $itemId . '"') . '>';
         if (empty($labelClass) && empty($label)) {
             $input .= $element;
         } elseif (isset($type) && ($type === 'checkbox' || $type === 'radio')) {
             $input .= '<label' . (empty($labelClass) ? '' : ' class="' . $labelClass . '"') . '>' . $element . '&nbsp;' . $label . '</label>';
         } else {
             $input .= '<label' . (empty($labelClass) ? '' : ' class="' . $labelClass . '"') . '>' . (empty($label) ? '' : $label . '&nbsp;') . $element . '</label>';
         }
         if (!empty($comment)) {
             $input .= '<div class="comment"' . (empty($id) ? '' : ' id="result_' . $id . '"') . '>' . $comment . '</div></div>';
         }
     } else {
         $itemClass .= isset($unit) ? ' wlabel' : '';
         $input = '<div class="' . $itemClass . '"' . (empty($itemId) ? '' : ' id="' . $itemId . '"') . '>';
         if (isset($type) && $type === 'checkbox') {
             $input .= '<label' . (empty($labelClass) ? '' : ' class="' . $labelClass . '"') . '>' . $element . '&nbsp;' . $label . '</label>';
         } else {
             if (isset($dataPreview)) {
                 $input .= '<div class=usericon><span><img src="' . $previewSrc . '" alt="Image preview" id=' . $dataPreview . '></span></div>';
             }
             if (isset($label) && isset($id)) {
                 $input .= '<label for="' . $id . '">' . $label . '</label>';
             }
             $input .= '<span' . (empty($labelClass) ? '' : ' class="' . $labelClass . '"') . '>' . $element . '</span>';
             if (isset($unit)) {
                 $input .= '<span class=label>' . $unit . '</span>';
             }
         }
         if (!empty($comment)) {
             $input .= '<div class="comment"' . (empty($id) ? '' : ' id="result_' . $id . '"') . '>' . $comment . '</div>';
         }
         $input .= '</div>';
     }
     return $input;
 }
Example #5
0
 /**
  * Generated from @assert (array('jpg','gif','png')) [==] "image/jpeg,image/gif,image/png".
  *
  * @covers Kotchasan\Mime::getEccept
  */
 public function testGetEccept()
 {
     $this->assertEquals("image/jpeg,image/gif,image/png", \Kotchasan\Mime::getEccept(array('jpg', 'gif', 'png')));
 }