/** * แสดงผล */ 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} & {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(); }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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} & {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(); }
/** * แสดงผล */ 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(); }
/** * แสดงผลกรอบ login * * @param array $login ข้อมูลการ Login * @return string ฟอร์ม */ public static function init($login) { // ฟอร์ม if ($login) { return createClass('Index\\Login\\View')->member($login); } else { return createClass('Index\\Login\\View')->login(); } }
/** * inint index */ public function index() { // ถ้าไม่มีโมดูลเลือกหน้า home $module = empty($_GET['module']) ? 'home' : $_GET['module']; // สร้าง View $view = $this->createView('Index\\Index\\View'); // template default $view->add(array('MENU' => createClass('Index\\Menu\\Controller')->render($module), 'TITLE' => 'Welcome to GCMS++', 'CONTENT' => \Template::load('', '', $module), 'TIME' => \Date::format())); // output เป็น HTML $view->renderHTML(); }
/** * แสดงผล * * @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(); }
/** * Useronline * * @param array $query_string */ public function index(Request $request) { // ตรวจสอบ Referer if ($request->initSession() && $request->isReferer()) { // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง define('MAIN_INIT', __FILE__); // เวลาปัจจุบัน $time = time(); // sesssion ปัจจุบัน $session_id = session_id(); // เวลาหมดอายุ $validtime = $time - self::$cfg->counter_gap; // ตาราง useronline $useronline = $this->getFullTableName('useronline'); // ลบคนที่หมดเวลาและตัวเอง $this->db()->delete($useronline, array(array('time', '<', $validtime), array('session', $session_id)), 0, 'OR'); // เพิ่มตัวเอง $save = array('time' => $time, 'session' => $session_id, 'ip' => $request->getClientIp()); $login = Login::isMember(); if ($login) { $save['member_id'] = (int) $login['id']; $save['displayname'] = $login['displayname'] == '' ? $login['email'] : $login['displayname']; } $this->db()->insert($useronline, $save); // คืนค่า user online $ret = array('time' => $time); // โหลด useronline ของ module $dir = ROOT_PATH . 'modules/'; $f = @opendir($dir); if ($f) { while (false !== ($text = readdir($f))) { if ($text != "." && $text != "..") { if (is_dir($dir . $text)) { if (is_file($dir . $text . '/controllers/useronline.php')) { include $dir . $text . '/controllers/useronline.php'; $class = ucfirst($text) . '\\Useronline\\Controller'; if (method_exists($class, 'index')) { $ret = createClass($class)->index($ret); } } } } } closedir($f); } // คืนค่า JSON echo json_encode($ret); } }
/** * แสดงผลโมดูล Index * * @param Request $request * @param Object $module ข้อมูลโมดูลจาก database * @return object||null คืนค่าข้อมูลหน้าที่เรียก ไม่พบคืนค่า null */ public function init(Request $request, $module) { // เรียกจากโมดูล index $index = null; if (!empty($module->module_id)) { $index = \Index\Index\Model::getIndex((int) $module->module_id); } elseif (!empty($module->id)) { $index = \Index\Index\Model::getIndexById((int) $module->id); } if ($index) { // view (index) return createClass('Index\\Index\\View')->render($index); } return null; }
/** * มาจากการเรียกด้วย Ajax * * @param Request $request */ public function index(Request $request) { // ตรวจสอบ Referer if ($request->initSession() && $request->isReferer()) { // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง define('MAIN_INIT', __FILE__); // กำหนด skin ให้กับ template Template::init(self::$cfg->skin); // ค่าจาก POST $query_string = $request->getParsedBody(); // เรียก Class ที่กำหนด if (!empty($query_string['class']) && preg_match('/^[a-zA-Z0-9]+$/', $query_string['method']) && method_exists($query_string['class'], $query_string['method'])) { $method = $query_string['method']; createClass($query_string['class'])->{$method}($request->withQueryParams($query_string)); } } }
/** * หน้าแก้ไขข้อมูลส่วนตัว * * @param Request $request * @return object */ public function render(Request $request) { if ($login = Login::isMember()) { // tab ที่เลือก $tab = $request->request('tab')->toString(); $member_tabs = array_keys(Gcms::$member_tabs); $tab = in_array($tab, $member_tabs) ? $tab : reset($member_tabs); $index = (object) array('description' => self::$cfg->web_description); // รายการ tabs $tabs = array(); if (!empty($login['fb'])) { unset(Gcms::$member_tabs['password']); } foreach (Gcms::$member_tabs as $key => $values) { if ($values[0] != '') { if ($key == $tab) { $class = "tab select {$key}"; $index->topic = Language::get($values[0]); $className = $values[1]; } else { $class = "tab {$key}"; } if (preg_match('/^http:\\/\\/.*/', $values[1])) { $tabs[] = '<li class="' . $class . '"><a href="' . $values[1] . '">' . Language::get($values[0]) . '</a></li>'; } else { $tabs[] = '<li class="' . $class . '"><a href="{WEBURL}index.php?module=editprofile&tab=' . $key . '">' . Language::get($values[0]) . '</a></li>'; } } } if (empty($className)) { // FB และแก้ไขรหัสผ่าน return createClass('Index\\PageNotFound\\Controller')->init($request, 'index'); } else { $template = Template::create('member', 'member', 'main'); $template->add(array('/{TAB}/' => implode('', $tabs), '/{DETAIL}/' => createClass($className)->render($request))); $index->detail = $template->render(); $index->keywords = $index->topic; // menu $index->menu = 'member'; return $index; } } else { // ไม่ได้ login return createClass('Index\\PageNotFound\\Controller')->init($request, 'index'); } }
/** * แสดงผล sitemap.xml * * @param Request $request */ public function index(Request $request) { // ตัวแปรป้องกันการเรียกหน้าเพจโดยตรง define('MAIN_INIT', __FILE__); // create Response $response = new Response(); // XML $content = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>'; $content .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'; $content .= ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'; $content .= ' xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9'; $content .= ' http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; // วันนี้ $cdate = date('Y-m-d'); // view $view = new \Index\Sitemap\View(); // หน้าหลัก $content .= $view->render(WEB_URL . 'index.php', $cdate); // โมดูลที่ติดตั้งแล้ว $modules = array(); $owners = array(); foreach (\Index\Sitemap\Model::getModules() as $item) { $modules[$item->id] = $item->module; $owners[$item->owner][] = $item->id; $content .= $view->render(Gcms::createUrl($item->module, '', 0, 0, $item->language == '' ? '' : 'lang=' . $item->language), $cdate); } // modules $dir = ROOT_PATH . 'modules/'; $f = @opendir($dir); if ($f) { while (false !== ($owner = readdir($f))) { if ($owner != '.' && $owner != '..' && $owner != 'index') { if (is_file($dir . $owner . '/controllers/sitemap.php')) { include $dir . $owner . '/controllers/sitemap.php'; foreach (createClass(ucfirst($owner) . '\\Sitemap\\Controller')->init($owners[$owner], $modules, $cdate) as $item) { $content .= $view->render($item->url, $item->date); } } } } closedir($f); } $content .= '</urlset>'; // send Response $response->withContent($content)->withHeader('Content-Type', 'application/xml; charset=UTF-8')->send(); }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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(); } }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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(); }
/** * แสดงผล */ 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} & {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(); } }
/** * แสดงผล */ 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(); }
/** * GLoader * * @param Request $request */ public function index(Request $request) { // session cookie $request->initSession(); // กำหนด skin ให้กับ template Template::init(self::$cfg->skin); // ตรวจสอบโมดูลที่เรียก $index = \Index\Export\Model::module($request->get('module')->toString()); if ($index) { $className = ucfirst($index->owner) . '\\Export\\Controller'; if (method_exists($className, 'init')) { $detail = createClass($className)->init($request, $index); } if ($detail != '') { $view = new \Kotchasan\View(); $view->setContents(array('/{CONTENT}/' => $detail)); echo $view->renderHTML(Template::load('', '', 'print')); exit; } } // ไม่พบโมดูลหรือไม่มีสิทธิ new \Kotchasan\Http\NotFound(); }
/** * หน้าส่งอีเมล์ * สมาชิกส่งจดหมายถึงสมาชิก และ แอดมิน * * @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); }
/** * แสดงผล */ 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(); } }
/** * แสดงผลโมดูล Index * * @param Request $request * @param Object $module ข้อมูลโมดูลจาก database * @return object||null คืนค่าข้อมูลหน้าที่เรียก ไม่พบคืนค่า null */ public function init(Request $request, $module) { return createClass('Index\\Search\\View')->render(\Index\Search\Model::findAll($request, $module)); }
/** * แสดงผล * * @param Request $request */ public function index(Request $request) { createClass('Index\\Index\\View')->render(); }
public function activate(Request $request) { return createClass('Index\\Activate\\View')->render($request); }
function exec($args, $stdin, &$stdout, &$stderr, &$system) { if (!isAdmin()) { $stderr = ucf(i18n("not enough rights to create class")); return true; } switch ($this->stage) { case 1: $this->name = $args; $stdout = "$args\n"; $stdout .= ucf(i18n("enter icon:")); $this->stage = 2; return false; case 2: $this->icon = $args; $stdout = "$args\n"; $stdout .= ucf(i18n("are you sure you want to create this class"))." (Y/n)?"; $this->stage = 3; return false; case 3: if (empty($args) || strtolower($args) == "y" || strtolower($args) == "yes") { $result = createClass($this->name, $this->icon); if (is_numeric($result) || $result === true) { $stdout = ucf(i18n("created new class successfully")); $this->stage = 0; return true; } $stderr = $result; $this->stage = 0; return true; } $stdout = ucf(i18n("aborted by user")); $this->stage = 0; return true; } if (empty($args)) { $stdout = ucf(i18n("enter name:")); $this->stage = 1; } else { $this->name = $args; $stdout .= ucf(i18n("enter icon:")); $this->stage = 2; } return false; }
/* Create Mocks */ $callbacks_during_save = array('beforeCreate','beforeValidation','beforeValidationOnUpdate','beforeValidationOnCreate','beforeSave','beforeUpdate','beforeDestroy', 'afterCreate','afterValidation','afterValidationOnUpdate','afterValidationOnCreate','afterSave','afterUpdate','afterDestroy'); function createClass ($classname, $parent, $functions, $function_body){ $class_code = "class $classname extends $parent {"; foreach ($functions as $function){ $class_code .= "public function $function(){".$function_body."}"; } $class_code .= "}"; eval($class_code); } createClass('TestCallback','ActiveRecord',$callbacks_during_save,'$this->__called[]=__FUNCTION__;return true;'); createClass('TestObserver','AkObserver',$callbacks_during_save,'$this->__called[]=__FUNCTION__;return true;'); /* Test */ class TestCase_AkActiveRecord_callbacks extends AkUnitTest { public function test_start() { $this->installAndIncludeModels(array('TestCallback'=>'id,name')); if (!isset($this->Observer)) $this->Observer = new TestObserver($this->TestCallback); } public function tearDown() { $this->Observer->__called = array(); }
/** * โหลด GCMS เพื่อแสดงผลหน้าเว็บไซต์ */ public function run() { return createClass(self::$defaultRouter)->inint(self::$defaultController); }
function handleCreateCourse() { global $classID, $className, $classes, $configFolderName, $dbConnection; global $session, $department, $courseNo, $sectionNo, $season; global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id; global $command, $commandState; global $Jenny_hashed_id, $Thomas_hashed_id; // get the command itself $command = Commands::CreateCourse; // get the state of the command $commandState = CommandStates::Execute; printOutputPageHeading($commandState); if (!empty($_POST)) { if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) { $errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>"; } else { $session = $_POST['session']; $season = $_POST['season']; } $is_SIS_course = $_POST['is_SIS_course']; if ($is_SIS_course == "yes") { $department = $_POST['department']; $courseNo = $_POST['course_number']; $sectionNo = $_POST['section_number']; $department = strtoupper($department); } else { $className = $_POST['course_name']; if (is_null($className) || strlen($className) == 0) { $errors .= "Error: You must enter a class name<br/>"; } } $instructorIDs = $_POST['instructor_id']; $taIDs = $_POST['TA_ids']; // validate inputs if (!empty($instructorIDs)) { $instructorIDs = UTIL_textArea2Array($instructorIDs); } else { $errors .= "Fatal Error: Instructor List is Empty!<br/><br/>"; } if (!empty($taIDs)) { $taIDs = UTIL_textArea2Array($taIDs); } // Extra admin hash ids, TODO: factor into an array for neatness $extraAdminHashIDs = array(); $extraAdminHashIDs[] = $Jenny_hashed_id; $extraAdminHashIDs[] = $Thomas_hashed_id; // Extra student hash ids $extraStudentHashIDs = array(); $extraStudentHashIDs[] = $yteststudent_hashed_id; if ($is_SIS_course == "yes") { if (is_null($courseNo) || strlen($courseNo) == 0) { $errors .= "Error: you must enter a course number<br/>"; } else { if (is_numeric(substr($courseNo, 0, 3))) { if (strlen($courseNo) == 4) { if (!is_alpha(substr($courseNo, 3, 1))) { $errors .= "Error: course number must be three digits plus an optional letter, ex. '300' or '300B'<br/><br/>"; } } } else { $errors .= "Error: course number must be three digits plus an optional letter, ex. '301' or '301A'<br/><br/>"; } } if (is_null($sectionNo) || strlen($sectionNo) == 0) { $errors .= "Error: you must enter a section number<br/>"; } else { // pad section number to three digits while (strlen($sectionNo) < 3) { $sectionNo = "0" . $sectionNo; } } // Assemble the name $className = getCourseName($department, $courseNo, $sectionNo); $className = $className . "_{$session}{$season}"; if (in_array($className, $classes)) { $errors .= "Error: {$className} already exists<br/><br/>"; } } else { $className = $className . "_{$session}{$season}"; if (in_array($className, $classes)) { $errors .= "Error: {$className} already exists<br/><br/>"; } } if (empty($errors)) { print "<b>Course Name to be Created: {$className}</b><br/><br/>"; print "<b>Instructors List:</b><br/>"; DEBUG_printSimpleArray($instructorIDs, 1); print "<br/><br/>"; print "<b>TA's List:</b><br/>"; DEBUG_printSimpleArray($taIDs, 1); print "<br/><br/>"; print "<b>Creating Instructor Account(s) if Not Yet Existed</b><br/>"; if (!empty($instructorIDs)) { // The rest of the debug messages (SQL output) goes into a text area, for neatness print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">"; print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">"; $instructorIDs = createUsers($instructorIDs, INSTRUCTOR, $dbConnection); print "</div></div><br/>"; } else { print "Nothing To Do...<br/><br/>"; } print "<b>"; if (!empty($taIDs)) { print "Creating Teaching Assistant Account(s) if Not Yet Existed<br/>"; } else { print "There are no TA's in the Course (for now)<br/><br/>"; } print "</b>"; if (!empty($taIDs)) { // The rest of the debug messages (SQL output) goes into a text area, for neatness print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">"; print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">"; $taIDs = createUsers($taIDs, TA, $dbConnection); print "</div></div><br/>"; } print "<b>"; if (!empty($extraAdminHashIDs)) { print "Creating Extra Administrator Account(s) - Arts Helpdesk, LC, etc.<br/>"; } else { print "There are no extra admin accounts in the course for now.<br/><br/>"; } print "</b>"; $extraAdminIDs = null; if (!empty($extraAdminHashIDs)) { // The rest of the debug messages (SQL output) goes into a text area, for neatness print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">"; print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">"; $extraAdminIDs = createUsers($extraAdminHashIDs, INSTRUCTOR, $dbConnection, true); print "</div></div><br/>"; } print "<b>"; if (!empty($extraStudentHashIDs)) { print "Creating Extra Student Account(s) for Testing (yteststudent, iteststu, bteststu)<br/>"; } else { print "There are no extra student accounts in the course for now.<br/><br/>"; } print "</b>"; $extraStudentIDs = null; if (!empty($extraStudentHashIDs)) { // The rest of the debug messages (SQL output) goes into a text area, for neatness print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">"; print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">"; $extraStudentIDs = createUsers($extraStudentHashIDs, STUDENT, $dbConnection, true); print "</div></div><br/>"; } // initial student list $studentIDs = $extraStudentIDs; // create and populate class $classID = createClass($className, $dbConnection); // merge admin lists $instructorIDs = array_merge($instructorIDs, $extraAdminIDs); addInstructorAndTAs($classID, $instructorIDs, $taIDs, $dbConnection); // create default groups $users = new users(); print "<b>Create Default Group {$className}" . "_everyone</b><br/><br/>"; $groupName = $className . "_everyone"; // This can deal with a null userID list, only instructorID and classID is utterly necessary $users->createGroup($groupName, $studentIDs, $instructorIDs, $classID); // Instructors and TA print "<b>Create Default Group {$className}" . "_instructorAndTA</b><br/><br/>"; $groupName = $className . "_instructorAndTA"; $users->createGroup($groupName, null, $instructorIDs, $classID); // set default UI for each user, first, let's merge all the arrays created so far. if (empty($taIDs)) { $allIDs = array_merge($instructorIDs, $studentIDs); } else { $allIDs = array_merge($instructorIDs, $taIDs, $studentIDs); } UTIL_setDefaultUISettings($allIDs); $users->close(); mysql_close($dbConnection); print "<h3>Course Creation Successful!</h3>"; printOutputPageFooting($commandState, $className); } else { print "{$errors}"; printOutputPageFooting(CommandStates::Error, $className); } } else { print "<br/><span style=\"color:red;font-weight:bold\">\r\n\t\t\t\tFATAL ERROR! POST parameter list empty. You may have found a bug.<br/>\r\n\t\t\t\tPlease email thomas.dang@ubc.ca with as much info as possible of the context when this error appears.<br/>\r\n\t\t\t\t</span>\r\n\t\t\t\t<br/>"; printOutputPageFooting(CommandStates::Error); } }