public static function getSemester($nim) { $config = new Model_Config(); $mahasiswa = new Model_Mahasiswa($nim); $tahun = $config->where('name', '=', 'tahun')->find()->value; $semester = $config->where('name', '=', 'semester')->find()->value; return ($tahun - $mahasiswa->tahun_masuk) * 2 + $semester; }
public function action_index() { // validation active Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List'))); $this->template->title = __('Translations'); //scan project files and generate .po $parse = $this->request->query('parse'); if ($parse) { //scan script require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php'); $obj = new POTCreator(); $obj->set_root(DOCROOT); $obj->set_exts('php'); $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i'); $obj->set_base_path('..'); $obj->set_read_subdir(true); $obj->write_pot(i18n::get_language_path()); Alert::set(Alert::SUCCESS, 'File regenerated'); } //change default site language if ($this->request->param('id')) { //save language $locale = new Model_Config(); $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find(); if (!$locale->loaded()) { $locale->group_name = 'i18n'; $locale->config_key = 'locale'; } $locale->config_value = $this->request->param('id'); try { $locale->save(); Alert::set(Alert::SUCCESS, __('Translations regenarated')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations'))); } //create language if (Core::post('locale')) { $language = $this->request->post('locale'); $folder = DOCROOT . 'languages/' . $language . '/LC_MESSAGES/'; // if folder does not exist, try to make it if (!file_exists($folder) and !@mkdir($folder, 0775, true)) { // mkdir not successful ? Alert::set(Alert::ERROR, __('Language folder cannot be created with mkdir. Please correct to be able to create new translation.')); HTTP::redirect(Route::url('oc-panel', array('controller' => 'translations'))); } // write an empty .po file for $language $out = 'msgid ""' . PHP_EOL; $out .= 'msgstr ""' . PHP_EOL; File::write($folder . 'messages.po', $out); Alert::set(Alert::SUCCESS, $this->request->param('id') . ' ' . __('Language saved')); } $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale'))); }
public function action_index() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Social Authentication for login'))); $this->template->title = __('Social Auth'); $this->template->styles = array('css/sortable.css' => 'screen'); $this->template->scripts['footer'][] = 'js/jquery-sortable-min.js'; //retrieve social_auth values $config = Social::get(); if ($p = $this->request->post()) { $confit_old = $config; $config_new = array(); foreach ($p as $key => $value) { if ($key != 'submit') { // check if its id, secret .. and build multy d. array, same as they have if (strpos($key, '_id')) { $config_new['providers'][str_replace('_id', '', $key)]['keys']['id'] = $value; } elseif (strpos($key, '_secret')) { $config_new['providers'][str_replace('_secret', '', $key)]['keys']['secret'] = $value; } elseif (strpos($key, '_key')) { $config_new['providers'][str_replace('_key', '', $key)]['keys']['key'] = $value; } elseif ($key == 'debug_mode') { $config_new[$key] = $value; } else { $config_new['providers'][$key]['enabled'] = $value; } } } // two fields not included $config_new['base_url'] = Route::url('default', array('controller' => 'social', 'action' => 'login', 'id' => 1)); $config_new['debug_file'] = DOCROOT . 'oc/vendor/hybridauth/logs.txt'; $obj_social_config = new Model_Config(); $conf = $obj_social_config->where('group_name', '=', 'social')->where('config_key', '=', 'config')->limit(1)->find(); if ($conf->loaded()) { $conf->config_value = json_encode($config_new); try { $conf->save(); $config = $config_new; //we update the form values if we changed them Alert::set(Alert::SUCCESS, __('Social Auth updated')); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } $this->template->content = View::factory('oc-panel/pages/social_auth/index', array('config' => $config)); }
public static function save($items) { // save widget to DB $conf = new Model_Config(); $conf->where('group_name', '=', 'general')->where('config_key', '=', 'menu')->limit(1)->find(); if (!$conf->loaded()) { $conf->group_name = 'general'; $conf->config_key = 'menu'; } $conf->config_value = json_encode($items); try { $conf->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } return FALSE; }
public function action_index() { // validation active Breadcrumbs::add(Breadcrumb::factory()->set_title(__('List'))); $this->template->title = __('Translations'); //scan project files and generate .po $parse = $this->request->query('parse'); if ($parse) { //scan script require_once Kohana::find_file('vendor', 'POTCreator/POTCreator', 'php'); $obj = new POTCreator(); $obj->set_root(DOCROOT); $obj->set_exts('php'); $obj->set_regular('/_[_|e]\\([\\"|\']([^\\"|\']+)[\\"|\']\\)/i'); $obj->set_base_path('..'); $obj->set_read_subdir(true); $obj->write_pot(i18n::get_language_path()); Alert::set(Alert::SUCCESS, 'File regenerated'); } //change default site language if ($this->request->param('id')) { //save language $locale = new Model_Config(); $locale->where('group_name', '=', 'i18n')->where('config_key', '=', 'locale')->limit(1)->find(); if (!$locale->loaded()) { $locale->group_name = 'i18n'; $locale->config_key = 'locale'; } $locale->config_value = $this->request->param('id'); try { $locale->save(); Alert::set(Alert::SUCCESS, ''); Request::current()->redirect(Route::url('oc-panel', array('controller' => 'translations'))); } catch (Exception $e) { echo $e; } } $this->template->content = View::factory('oc-panel/pages/translations/index', array('languages' => i18n::get_languages(), 'current_language' => core::config('i18n.locale'))); }
/** * saves thme options as json 'theme.NAMETHEME' = array json * @param string $theme theme to save at * @param array $data to save * @return void */ public static function save($theme = NULL, $data = NULL) { if ($theme === NULL) { $theme = self::$theme; } if ($data === NULL) { $data = self::$data; } // save theme to DB $conf = new Model_Config(); $conf->where('group_name', '=', 'theme')->where('config_key', '=', $theme)->limit(1)->find(); if (!$conf->loaded()) { $conf->group_name = 'theme'; $conf->config_key = $theme; } $conf->config_value = json_encode($data); try { $conf->save(); } catch (Exception $e) { throw new HTTP_Exception_500(); } }
/** * Plugins configuration * @return [view] Renders view with form inputs */ public function action_plugins() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Plugins'))); $this->template->title = __('Plugins'); // all form config values $generalconfig = new Model_Config(); $config = $generalconfig->where('group_name', '=', 'general')->or_where('group_name', '=', 'i18n')->find_all(); // config general array foreach ($config as $c) { $forms[$c->config_key] = $forms[$c->config_key] = array('key' => $c->group_name . '[' . $c->config_key . '][]', 'id' => $c->config_key, 'value' => $c->config_value); } // save only changed values if ($this->request->post()) { //d($this->request->post()); foreach ($this->request->post('general') as $k => $v) { $this->request->post('general_' . $k, $v[0]); } $validation = Validation::factory($this->request->post()); if ($validation->check()) { //save general foreach ($config as $c) { $config_res = $this->request->post(); if (isset($config_res[$c->group_name][$c->config_key][0]) and $config_res[$c->group_name][$c->config_key][0] != $c->config_value) { $c->config_value = $config_res[$c->group_name][$c->config_key][0]; Model_Config::set_value($c->group_name, $c->config_key, $c->config_value); } } } else { $errors = $validation->errors('config'); foreach ($errors as $error) { Alert::set(Alert::ALERT, $error); } $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'plugins'))); } Alert::set(Alert::SUCCESS, __('Plugins configuration updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'plugins'))); } $this->template->content = View::factory('oc-panel/pages/settings/plugins', array('forms' => $forms)); }
/** * Image configuration * @return [view] Renders view with form inputs */ public function action_image() { $this->template->scripts['footer'][] = 'js/jquery.validate.min.js'; $this->template->scripts['footer'][] = '/js/oc-panel/settings.js'; Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Image'))); $this->template->title = __('Image'); // all form config values $imageconf = new Model_Config(); $config = $imageconf->where('group_name', '=', 'image')->find_all(); // save only changed values if ($this->request->post()) { foreach ($this->request->post('image') as $k => $v) { $this->request->post('image_' . $k, $v[0]); } $validation = Validation::factory($this->request->post())->rule('image_max_image_size', 'not_empty')->rule('image_max_image_size', 'digit')->rule('image_height', 'digit')->rule('image_width', 'not_empty')->rule('image_width', 'digit')->rule('image_height_thumb', 'not_empty')->rule('image_height_thumb', 'digit')->rule('image_width_thumb', 'not_empty')->rule('image_width_thumb', 'digit')->rule('image_quality', 'not_empty')->rule('image_quality', 'digit')->rule('image_quality', 'range', array(':value', 1, 100))->rule('image_watermark', 'range', array(':value', 0, 1))->rule('image_watermark_position', 'not_empty')->rule('image_watermark_position', 'digit')->rule('image_watermark_position', 'range', array(':value', 0, 2))->rule('image_disallow_nudes', 'range', array(':value', 0, 1))->rule('image_aws_s3_active', 'range', array(':value', 0, 1)); if ($validation->check()) { foreach ($config as $c) { $config_res = $this->request->post(); if (!array_key_exists('allowed_formats', $config_res[$c->group_name])) { Alert::set(Alert::ERROR, __('At least one image format should be allowed.')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'image'))); } if ($config_res[$c->group_name][$c->config_key][0] != $c->config_value) { if ($c->config_key == 'allowed_formats') { $allowed_formats = ''; foreach ($config_res[$c->group_name][$c->config_key] as $key => $value) { $allowed_formats .= $value . ","; } $config_res[$c->group_name][$c->config_key][0] = $allowed_formats; } if ($c->config_key == 'aws_s3_domain') { switch ($config_res[$c->group_name]['aws_s3_domain'][0]) { case 'bn-s3': $s3_domain = $config_res[$c->group_name]['aws_s3_bucket'][0] . '.s3.amazonaws.com'; break; case 'bn': $s3_domain = $config_res[$c->group_name]['aws_s3_bucket'][0]; break; default: $s3_domain = 's3.amazonaws.com/' . $config_res[$c->group_name]['aws_s3_bucket'][0]; break; } $config_res[$c->group_name][$c->config_key][0] = $s3_domain . '/'; } $c->config_value = $config_res[$c->group_name][$c->config_key][0]; Model_Config::set_value($c->group_name, $c->config_key, $c->config_value); } } } else { $errors = $validation->errors('config'); foreach ($errors as $error) { Alert::set(Alert::ALERT, $error); } $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'image'))); } Alert::set(Alert::SUCCESS, __('Image Configuration updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'image'))); } $this->template->content = View::factory('oc-panel/pages/settings/image', array('config' => $config)); }
/** * changes the order to display fields * @param array $order * @return bool */ public function change_order(array $order) { $fields = self::get_all(); $new_fields = array(); //using order they send us foreach ($order as $name) { if (isset($fields[$name])) { $new_fields[$name] = $fields[$name]; } } //save configs $conf = new Model_Config(); $conf->where('group_name', '=', 'advertisement')->where('config_key', '=', 'fields')->limit(1)->find(); if ($conf->loaded()) { try { $conf->config_value = json_encode($new_fields); $conf->save(); return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } return FALSE; }
/** * delete current widget data from the DB config * @return boolean */ public function delete() { if ($this->loaded) { // save widget to DB $confw = new Model_Config(); $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find(); if ($confw->loaded()) { try { $confw->delete(); //remove from previous placeholder, only if they are different $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find(); if ($confp->loaded()) { //remove the key $wid = json_decode($confp->config_value); if (is_array($wid)) { $wid = array_diff($wid, array($this->widget_name)); $confp->config_value = json_encode(array_values($wid)); $confp->save(); } } $this->data = array(); $this->loaded = FALSE; return TRUE; } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } return FALSE; }
public function action_sitemap() { $this->template->title = __('Sitemap'); Breadcrumbs::add(Breadcrumb::factory()->set_title($this->template->title)); // all sitemap config values $sitemapconfig = new Model_Config(); $config = $sitemapconfig->where('group_name', '=', 'sitemap')->find_all(); // save only changed values if ($this->request->post()) { foreach ($config as $c) { $config_res = $this->request->post($c->config_key); if ($config_res != $c->config_value) { $c->config_value = $config_res; try { $c->save(); } catch (Exception $e) { throw HTTP_Exception::factory(500, $e->getMessage()); } } } // Cache::instance()->delete_all(); Alert::set(Alert::SUCCESS, __('Sitemap Configuration updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'tools', 'action' => 'sitemap'))); } //force regenerate sitemap if (Core::get('force') == 1) { Alert::set(Alert::SUCCESS, Sitemap::generate()); } $this->template->content = View::factory('oc-panel/pages/tools/sitemap'); }
/** * affiliate configuration can be configured here * @return [view] Renders view with form inputs */ public function action_affiliates() { Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Affiliates'))); $this->template->title = __('Affiliates'); $this->template->scripts['footer'][] = 'js/jquery.validate.min.js'; $this->template->scripts['footer'][] = 'js/oc-panel/settings.js'; // all form config values $paymentconf = new Model_Config(); $config = $paymentconf->where('group_name', '=', 'affiliate')->find_all(); // save only changed values if ($this->request->post()) { $validation = Validation::factory($this->request->post())->rule('active', 'range', array(':value', 0, 1))->rule('cookie', 'not_empty')->rule('cookie', 'digit')->rule('payment_days', 'not_empty')->rule('payment_days', 'digit')->rule('payment_min', 'not_empty')->rule('payment_min', 'digit'); if ($validation->check()) { foreach ($config as $c) { $config_res = $this->request->post($c->config_key); if ($config_res != $c->config_value) { $c->config_value = $config_res; try { $c->save(); } catch (Exception $e) { echo $e; } } } } else { $errors = $validation->errors('config'); foreach ($errors as $error) { Alert::set(Alert::ALERT, $error); } $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'affiliates'))); } Alert::set(Alert::SUCCESS, __('Affiliate Configuration updated')); $this->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'affiliates'))); } $pages = array('' => __('Deactivated')); foreach (Model_Content::get_pages() as $key => $value) { $pages[$value->seotitle] = $value->title; } $this->template->content = View::factory('oc-panel/pages/settings/affiliates', array('config' => $config, 'pages' => $pages)); }
public function action_saveplaceholders() { //deleting the fragment cache...a bit ugly but works. View::delete_fragment('sidebar_front'); View::delete_fragment('footer_front'); $this->auto_render = FALSE; $this->template = View::factory('js'); DB::delete('config')->where('group_name', '=', 'placeholder')->execute(); //for each placeholder foreach ($_GET as $placeholder => $widgets) { if (!is_array($widgets)) { $widgets = array($widgets); } // save palceholder to DB $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $placeholder)->limit(1)->find(); if (!$confp->loaded()) { $confp->group_name = 'placeholder'; $confp->config_key = $placeholder; } $confp->config_value = json_encode($widgets); $confp->save(); //edit each widget change placeholder foreach ($widgets as $wname) { $w = Widget::factory($wname); if ($w !== NULL) { if ($w->loaded and $w->placeholder != $placeholder) { $w->placeholder = $placeholder; $w->save(); } } } } $this->template->content = __('Saved'); }
/** * Payment deatails and paypal configuration can be configured here * @return [view] Renders view with form inputs */ public function action_payment() { // validation active //$this->template->scripts['footer'][]= '/js/oc-panel/settings.js'; Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Payments'))); $this->template->title = __('Payments'); // all form config values $paymentconf = new Model_Config(); $config = $paymentconf->where('group_name', '=', 'payment')->find_all(); $paypal_currency = Paypal::get_currency(); // currencies limited by paypal // save only changed values if ($this->request->post()) { foreach ($config as $c) { $config_res = $this->request->post($c->config_key); if ($c->config_key == 'paypal_currency') { $config_res = $paypal_currency[core::post('paypal_currency')]; } if ($config_res != $c->config_value) { $c->config_value = $config_res; try { $c->save(); } catch (Exception $e) { echo $e; } } } Alert::set(Alert::SUCCESS, __('General Configuration updated')); $this->request->redirect(Route::url('oc-panel', array('controller' => 'settings', 'action' => 'payment'))); } $this->template->content = View::factory('oc-panel/pages/settings/payment', array('config' => $config, 'paypal_currency' => $paypal_currency)); }
/** * delete current widget data from the DB config * @return boolean */ public function delete() { if ($this->loaded) { // save widget to DB $confw = new Model_Config(); $confw->where('group_name', '=', 'widget')->where('config_key', '=', $this->widget_name)->limit(1)->find(); if ($confw->loaded()) { try { $confw->delete(); //remove from previous placeholder, only if they are different $confp = new Model_Config(); $confp->where('group_name', '=', 'placeholder')->where('config_key', '=', $this->placeholder)->limit(1)->find(); if ($confp->loaded()) { //remove the key $wid = json_decode($confp->config_value); if (is_array($wid)) { $key = array_search($this->widget_name, $wid); if ($key !== FALSE) { unset($wid[$key]); } $confp->config_value = json_encode($wid); $confp->save(); } } $this->data = array(); $this->loaded = FALSE; return TRUE; } catch (Exception $e) { throw new HTTP_Exception_500($e); } } } return FALSE; }