Ejemplo n.º 1
0
 /**
  * จัดรูปแบบการแสดงผลในแต่ละแถว
  *
  * @param array $item
  * @return array
  */
 public function onRow($item)
 {
     $item['topic'] = '<a href="../index.php?module=index&amp;id=' . $item['id'] . '" target="preview">' . $item['topic'] . '</a>';
     $item['last_update'] = Date::format($item['last_update'], 'd M Y H:i');
     $item['language'] = empty($item['language']) ? '' : '<img src="' . WEB_URL . 'language/' . $item['language'] . '.gif" alt="' . $item['language'] . '">';
     $item['published'] = '<a id=published_' . $item['id'] . ' class="icon-published' . $item['published'] . '" title="' . $this->publisheds[$item['published']] . '"></a>';
     return $item;
 }
Ejemplo n.º 2
0
 /**
  * จัดรูปแบบการแสดงผลในแต่ละแถว
  *
  * @param array $item
  * @return array
  */
 public function onRow($item)
 {
     $publisheds = Language::get('PUBLISHEDS');
     $item['published'] = '<a id=published_' . $item['id'] . ' class="icon-published' . $item['published'] . '" title="' . $publisheds[$item['published']] . '"></a>';
     $item['last_update'] = Date::format($item['last_update'], 'd M Y H:i');
     $item['language'] = empty($item['language']) ? '' : '<img src="' . WEB_URL . 'language/' . $item['language'] . '.gif" alt="' . $item['language'] . '">';
     return $item;
 }
Ejemplo n.º 3
0
 /**
  * อ่านข้อมูลโมดูลจากชื่อโมดูล
  *
  * @param string $module
  * @param type $owner
  * @return object|false คืนค่าข้อมูล object ไม่พบ คืนค่า false
  */
 public static function getModule($module, $owner)
 {
     if (is_string($module) && is_string($owner)) {
         $model = new \Kotchasan\Model();
         $select = array('I.id', 'I.module_id', 'M.module', 'M.owner', 'D.topic', 'D.description', 'D.keywords', 'D.detail', 'I.visited');
         $where = array(array('I.index', 1), array('M.module', $module), array('M.owner', $owner), array('I.published', 1), array('I.published_date', '<=', Date::mktimeToSqlDate(time())), array('D.language', array(Language::name(), '')));
         return $model->db()->createQuery()->from('index I')->join('modules M', 'INNER', array('M.id', 'I.module_id'))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'M.id'), array('D.language', 'I.language')))->where($where)->cacheOn()->first($select);
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * จัดรูปแบบการแสดงผลในแต่ละแถว
  *
  * @param array $item
  * @return array
  */
 public function onRow($item)
 {
     $item['email'] = '<a href="index.php?module=sendmail&to=' . $item['email'] . '" class="status' . $item['status'] . '">' . $item['email'] . '</a>';
     $item['create_date'] = Date::format($item['create_date'], 'd M Y');
     $item['lastvisited'] = Date::format($item['lastvisited'], 'd M Y H:i') . ' (' . number_format($item['visited']) . ')';
     $item['sex'] = '<span class=icon-sex' . (isset($this->sexes[$item['sex']]) ? '-' . $item['sex'] : '') . '></span>';
     $item['ban'] = $item['ban'] == 1 ? '<span class="icon-ban ban" title="{LNG_Members were suspended}"></span>' : '<span class="icon-ban"></span>';
     $item['phone1'] = empty($item['phone1']) ? '' : '<a href="tel:' . $item['phone1'] . '">' . $item['phone1'] . '</a>';
     $class = $item['fb'] == 1 ? ' class=facebook' : '';
     $item['displayname'] = empty($item['website']) ? '<span' . $class . '>' . $item['displayname'] . '</span>' : '<a href="http://' . $item['website'] . '" target="_blank"' . $class . '>' . $item['displayname'] . '</a>';
     return $item;
 }
Ejemplo n.º 5
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // เริ่มต้นการใช้งาน Template
     Template::init(self::$cfg->skin);
     // ถ้าไม่มีโมดูลเลือกหน้า home
     $module = $request->get('module', 'home')->toString();
     // สร้าง View
     $view = new \Kotchasan\View();
     // template default
     $view->setContents(array('/{MENU}/' => createClass('Index\\Menu\\Controller')->render($module), '/{TITLE}/' => self::$cfg->web_title, '/{CONTENT}/' => Template::load('', '', $module), '/{TIME}/' => Date::format()));
     // ส่งออกเป็น HTML
     echo $view->renderHTML();
 }
Ejemplo n.º 6
0
 /**
  * อ่านหน้าเพจ
  * id = 0 สร้างหน้าใหม่
  *
  * @param int $id
  * @param string $owner
  * @return object|null คืนค่า object ของข้อมูล ไม่พบคืนค่า null
  */
 public static function getIndex($id, $owner)
 {
     if (is_int($id)) {
         if (empty($id)) {
             // ใหม่
             $index = (object) array('owner' => $owner, 'id' => 0, 'published' => 1, 'module' => '', 'topic' => '', 'keywords' => '', 'description' => '', 'detail' => '', 'last_update' => 0, 'published_date' => Date::mktimeToSqlDate(), 'language' => '');
         } else {
             // แก้ไข
             $model = new static();
             $select = array('I.id', 'I.language', 'D.topic', 'D.keywords', 'D.description', 'D.detail', 'I.last_update', 'I.published', 'I.published_date', 'M.module', 'M.owner');
             $index = $model->db()->createQuery()->select($select)->from('index I')->join('modules M', 'INNER', array(array('M.id', 'I.module_id')))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'I.module_id'), array('D.language', 'I.language')))->where(array(array('I.id', $id), array('I.index', 1)))->limit(1)->execute();
             $index = sizeof($index) == 1 ? $index[0] : null;
         }
         return $index;
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * แสดงผล
  *
  * @param Request $request
  */
 public function index(Request $request)
 {
     // อ่านรายชื่อฟิลด์ของตาราง
     $rs = Recordset::create('Index\\World\\Model');
     $result = $rs->find(100);
     $fields = $rs->getFields();
     echo implode(', ', array_keys($fields)) . '<br>';
     // ลบข้อมูลทั้งตาราง
     $rs->emptyTable();
     // insert new record
     for ($i = 0; $i < 10000; $i++) {
         $query = World::create();
         $query->updated_at = Date::mktimeToSqlDateTime();
         $query->save();
     }
     // อัปเดททุก record
     $rs->updateAll(array('created_at' => Date::mktimeToSqlDateTime()));
     // อ่านจำนวนข้อมูลทั้งหมดในตาราง
     echo 'All ' . $rs->count() . ' records.<br>';
     // สุ่ม record มาแก้ไข
     for ($i = 0; $i < 5; $i++) {
         $rnd = rand(1, 10000);
         $world = $rs->find($rnd);
         $world->name = 'Hello World!';
         $world->save();
     }
     // query รายการที่มีการแก้ไข
     $rs->where(array('name', '!=', ''));
     // อ่านจำนวนข้อมูลที่พบ
     echo 'Found ' . $rs->count() . ' records.<br>';
     // แสดงผลรายการที่พบ
     foreach ($rs->all('id', 'name') as $item) {
         echo $item->id . '=' . $item->name . '<br>';
         // ลบรายการที่กำลังแสดงผล
         $item->delete();
     }
     // อ่านรายชื่อฟิลด์ของ query
     $fields = $rs->getFields();
     echo implode(', ', array_keys($fields)) . '<br>';
     // อ่านจำนวนข้อมูลที่เหลือ
     echo 'Remain ' . Recordset::create('Index\\World\\Model')->count() . ' records.<br>';
 }
Ejemplo n.º 8
0
 /**
  * ฟังก์ชั่นส่งเมล์จากแม่แบบจดหมาย
  *
  * @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);
     }
 }
Ejemplo n.º 9
0
 public function view(Request $request)
 {
     $topic = Language::get('Personal information') . ' ' . self::$cfg->web_title;
     $user = \Index\Member\Model::getUserById($request->get('id')->toInt());
     if ($user) {
         $template = Template::create('member', 'member', 'view');
         $template->add(array('/{ID}/' => $user->id, '/{EMAIL}/' => $user->email, '/{FNAME}/' => $user->fname, '/{LNAME}/' => $user->lname, '/{SEX}/' => $user->sex === 'f' || $user->sex === 'm' ? $user->sex : 'u', '/{DATE}/' => Date::format($user->create_date), '/{WEBSITE}/' => $user->website, '/{VISITED}/' => $user->visited, '/{LASTVISITED}/' => Date::format($user->lastvisited), '/{POST}/' => number_format($user->post), '/{REPLY}/' => number_format($user->reply), '/{STATUS}/' => isset(self::$cfg->member_status[$user->status]) ? self::$cfg->member_status[$user->status] : 'Unknow', '/{COLOR}/' => $user->status, '/{SOCIAL}/' => $user->fb == 1 ? 'icon-facebook' : '', '/{TOPIC}/' => $topic));
         // breadcrumbs
         $canonical = WEB_URL . 'index.php?module=member&amp;id=' . $user->id;
         Gcms::$view->addBreadcrumb($canonical, $topic);
         // คืนค่า
         return (object) array('detail' => $template->render(), 'keywords' => self::$cfg->web_title, 'description' => self::$cfg->web_description, 'topic' => $topic, 'canonical' => $canonical);
     } else {
         // ไม่พบสมาชิก
         return createClass('Index\\PageNotFound\\Controller')->init($request, 'index');
     }
 }
Ejemplo n.º 10
0
 /**
  * Generated from @assert ('2016-02-01 00:00:00') [==] 1454259600.
  *
  * @covers Kotchasan\Date::sqlDateTimeToMktime
  */
 public function testSqlDateTimeToMktime()
 {
     $this->assertEquals(1454259600, \Kotchasan\Date::sqlDateTimeToMktime('2016-02-01 00:00:00'));
 }
Ejemplo n.º 11
0
 /**
  * title bar
  */
 public function title()
 {
     return '{LNG_Visitors report} ' . Date::format($this->date, 'd M Y');
 }
Ejemplo n.º 12
0
 /**
  * module=dashboard
  *
  * @return string
  */
 public function render()
 {
     $dashboard = new \Index\Dashboard\Model();
     // colors
     $colors = array('#7E57C2', '#FF5722', '#E91E63', '#259B24', '#607D8B', '#2CB6D5', '#FD971F', '#26A694', '#FF5722', '#00BCD4', '#8BC34A', '#616161', '#FFD54F', '#03A9F4', '#795548');
     // ข้อมูล counter
     $counter = $dashboard->counter();
     if (!$counter) {
         $counter = array('counter' => 0, 'visited' => 0, 'members' => 0, 'activate' => 0, 'ban' => 0, 'useronline' => 0);
     }
     $content = array();
     $content[] = '<div class="infobox clear"><ul>';
     Gcms::$dashboard_menus[] = array('clock', '{LNG_Visitors today}', 'index.php?module=report', number_format($counter['visited']), 'visited');
     Gcms::$dashboard_menus[] = array('users', '{LNG_People online}', '', number_format($counter['useronline']), 'useronline');
     $l = sizeof($colors);
     foreach (Gcms::$dashboard_menus as $i => $items) {
         $z = $i % $l;
         $row = '<li class="table" style="border-color:' . $colors[$z] . '">';
         $row .= '<span class="td icon-' . $items[0] . '" style="background-color:' . $colors[$z] . '"></span>';
         $d = !empty($items[4]) ? ' id="' . $items[4] . '"' : '';
         $t = $items[3] == '' ? '' : '<span class=c-' . $i . $d . '>' . $items[3] . '</span>';
         if ($items[2] == '') {
             $row .= '<span class="detail td">' . $t . $items[1] . '</span>';
         } else {
             $row .= '<a class="detail td" href="' . $items[2] . '">' . $t . $items[1] . '</a>';
         }
         $row .= '</li>';
         $content[] = $row;
     }
     $content[] = '</ul></div>';
     $content[] = '<div class="ggrid collapse dashboard">';
     $content[] = '<div class="block4 float-left">';
     // site report
     $content[] = '<section class=section>';
     $content[] = '<header><h1 class=icon-summary>{LNG_Overview report of the system}</h1></header>';
     $content[] = '<table class="summary fullwidth">';
     $content[] = '<caption>{LNG_Overview and summary of this site}</caption>';
     $content[] = '<tbody>';
     $content[] = '<tr><th scope=row><a href="' . WEB_URL . 'admin/index.php?module=member&amp;sort=id%20desc">{LNG_Total Members}</a></th><td class=right>' . number_format($counter['members']) . ' {LNG_people}</td></tr>';
     $content[] = '<tr class=bg2><th scope=row><a href="' . WEB_URL . 'admin/index.php?module=member&amp;sort=activatecode%20desc,id%20desc">{LNG_Members who have not confirmed the email}</a></th><td class=right>' . number_format($counter['activate']) . ' {LNG_people}</td></tr>';
     $content[] = '<tr><th scope=row><a href="' . WEB_URL . 'admin/index.php?module=member&amp;sort=ban%20desc,id%20desc">{LNG_Members were suspended}</a></th><td class=right>' . number_format($counter['ban']) . ' {LNG_people}</td></tr>';
     $content[] = '<tr class=bg2><th scope=row>{LNG_Visitors total}</th><td class=right>' . number_format($counter['counter']) . ' {LNG_people}</td></tr>';
     $content[] = '<tr><th scope=row>{LNG_People online}</th><td class=right>' . number_format($counter['useronline']) . ' {LNG_people}</td></tr>';
     $content[] = '<tr class=bg2><th scope=row><a href="' . WEB_URL . 'admin/index.php?module=report">{LNG_Visitors today}</a></th><td class=right>' . number_format($counter['visited']) . ' {LNG_people}</td></tr>';
     if (is_file(ROOT_PATH . DATA_FOLDER . 'index.php')) {
         $date = file_get_contents(ROOT_PATH . DATA_FOLDER . 'index.php');
         if (preg_match('/([0-9]+){0,2}-([0-9]+){0,2}-([0-9]+){0,4}\\s([0-9]+){0,2}:([0-9]+){0,2}:([0-9]+){0,2}/', $date, $match)) {
             $cron_time = Date::format(mktime($match[4], $match[5], $match[6], $match[2], $match[1], $match[3]));
         } else {
             $cron_time = '-';
         }
     } else {
         $cron_time = '-';
     }
     $content[] = '<tr><th scope=row>{LNG_Cron last running at}</th><td class=right>' . $cron_time . '</td></tr>';
     $content[] = '</tbody>';
     $content[] = '<tfoot>';
     $content[] = '<tr><td colspan=2 class=right>{LNG_You are currently using GCMS version} <em>{VERSION}</em></td></tr>';
     $content[] = '</tfoot>';
     $content[] = '</table>';
     $content[] = '</section>';
     // news
     $content[] = '<section class=section>';
     $content[] = '<header><h1 class=icon-rss>{LNG_News}</h1></header>';
     $content[] = '<ol id=news_div></ol>';
     $content[] = '<div class="bottom right padding-top-right">';
     $content[] = '<a class=icon-next href="http://gcms.in.th/news.html" target=_blank>{LNG_all items}</a>';
     $content[] = '</div>';
     $content[] = '</section>';
     $content[] = '</div>';
     $content[] = '<div class="block8 float-right">';
     // page view
     $pageviews = $dashboard->pageviews();
     $y = (int) date('Y');
     $pages_view = 0;
     $pageview = array();
     $visited = array();
     $thead = array();
     $l = sizeof($pageviews);
     foreach ($pageviews as $i => $item) {
         $c = $i > $l - 8 ? $i > $l - 4 ? '' : 'mobile' : 'tablet';
         $thead[] = '<td class="' . $c . '"><a href="' . WEB_URL . 'admin/index.php?module=pagesview&amp;date=' . $item['year'] . '-' . $item['month'] . '">' . Date::monthName($item['month']) . '</a></td>';
         $pageview[] = '<td class="' . $c . '">' . number_format($item['pages_view']) . '</td>';
         $visited[] = '<td class="' . $c . '">' . number_format($item['visited']) . '</td>';
     }
     $content[] = '<section class=section>';
     $content[] = '<header><h1 class=icon-stats>{LNG_People visit the site}</h1></header>';
     $content[] = '<div id=pageview_graph class=ggraphs>';
     $content[] = '<canvas></canvas>';
     $content[] = '<table class="data fullwidth border">';
     $content[] = '<thead><tr><th>{LNG_monthly}</th>' . implode('', $thead) . '</tr></thead>';
     $content[] = '<tbody>';
     $content[] = '<tr><th scope=row>{LNG_Visitors total}</th>' . implode('', $visited) . '</tr>';
     $content[] = '<tr class=bg2><th scope=row>{LNG_Pages view}</th>' . implode('', $pageview) . '</tr>';
     $content[] = '</tbody>';
     $content[] = '</table>';
     $content[] = '</div>';
     $content[] = '</section>';
     // popular page
     $thead = array();
     $visited = array();
     foreach ($dashboard->popularpage() as $item) {
         $thead[] = '<td>' . $item['topic'] . '</td>';
         $visited[] = '<td>' . $item['visited_today'] . '</td>';
     }
     $content[] = '<section class=section>';
     $content[] = '<header><h1 class=icon-pie>{LNG_Popular daily} ({LNG_Module} Document)</h1></header>';
     $content[] = '<div id=visited_graph class=ggraphs>';
     $content[] = '<canvas></canvas>';
     $content[] = '<table class=hidden>';
     $content[] = '<thead><tr><th>&nbsp;</th>' . implode('', $thead) . '</tr></thead>';
     $content[] = '<tbody>';
     $content[] = '<tr><th>{LNG_Visited}</th>' . implode('', $visited) . '</tr>';
     $content[] = '</tbody>';
     $content[] = '</table>';
     $content[] = '</div>';
     $content[] = '</section>';
     $content[] = '</div>';
     $content[] = '</section>';
     $content[] = '</div>';
     $content[] = '</div>';
     $content[] = '<script>';
     $content[] = '$G(window).Ready(function(){';
     // สี สำหรับส่งให้ graphs
     $color = "['" . implode("', '", $colors) . "']";
     $content[] = 'new GGraphs("pageview_graph", {type:"line",colors:' . $color . '});';
     $content[] = 'new GGraphs("visited_graph", {type:"pie",colors:' . $color . ',centerX:30+Math.round($G("visited_graph").getHeight()/2),labelOffset:35,pieMargin:30,strokeColor:null});';
     $content[] = "getNews('news_div');";
     $content[] = "getUpdate('" . self::$cfg->version . "');";
     $content[] = '});';
     $content[] = '</script>';
     return implode('', $content);
 }