function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     if (isset($form->data['chrono_security_answer'])) {
         $session = \GCore\Libs\Base::getSession();
         $session_key = $config->get('session_key', '');
         if (empty($session_key)) {
             $session_key = $form->form['Form']['title'];
         }
         $sessionvar = $session->get("chrono_security_answers_" . $session_key, array());
         $session->clear("chrono_security_answers_" . $session_key);
         $chrono_security_answer = strtolower(trim($form->data['chrono_security_answer']));
         if (!in_array($chrono_security_answer, $sessionvar)) {
             $this->events['fail'] = 1;
             $form->errors['chrono_security_answer'] = $config->get('error', "You have entered a wrong security question's answer.");
             $form->data['chrono_security_answer'] = '';
             $form->debug[$action_id][self::$title][] = "Failed the answer check!";
         } else {
             $this->events['success'] = 1;
             $form->data['chrono_security_answer'] = '';
             $form->debug[$action_id][self::$title][] = "Passed the answer check!";
         }
     } else {
         $this->events['fail'] = 1;
         $form->errors['chrono_security_answer'] = $config->get('error', "You have entered a wrong security question's answer.");
         $form->debug[$action_id][self::$title][] = "Couldn't find the answer field value in the \$_POST array!";
     }
 }
예제 #2
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     $session_key = $config->get('session_key', '');
     if (empty($session_key)) {
         $session_key = $form->form['Form']['title'];
     }
     $sessionvar = $session->get('chrono_honeypot_' . $session_key, array());
     $session->clear('chrono_honeypot_' . $session_key);
     $field_name = !empty($sessionvar['name']) ? $sessionvar['name'] : '';
     $time = !empty($sessionvar['time']) ? $sessionvar['time'] : time();
     //check field exists
     if (!empty($field_name) and !empty($form->data[$field_name])) {
         //check time
         if ((int) $config->get('time', 5) + $time > time()) {
             $this->events['fail'] = 1;
             $form->errors['chrono_honeypot'] = $config->get('error', "Honeypot check failed.");
             $form->debug[$action_id][self::$title][] = "Time too short";
             return false;
         }
     } else {
         $this->events['fail'] = 1;
         $form->errors['chrono_honeypot'] = $config->get('error', "Honeypot check failed.");
         $form->debug[$action_id][self::$title][] = "Token mismatch";
         return false;
     }
     $this->events['success'] = 1;
     $form->debug[$action_id][self::$title][] = "Honeypot check passed.";
     return true;
 }
예제 #3
0
 public static function on_editor_load()
 {
     self::$settings = \GCore\Libs\Base::getSettings('editors');
     if (self::$settings->get('active_editor', 'tinymce') == 'tinymce') {
         $doc = \GCore\Libs\Document::getInstance();
         //$doc->_('jquery');
         $doc->addJsFile(\GCore\C::get('GCORE_FRONT_URL') . 'extensions/editors/assets/tinymce/tinymce.min.js');
         return true;
     } else {
         if (self::$settings->get('active_editor', 'tinymce') == 'ckeditor') {
             $doc = \GCore\Libs\Document::getInstance();
             $doc->_('jquery');
             $doc->addJsFile(\GCore\C::get('GCORE_FRONT_URL') . 'extensions/editors/assets/ckeditor/ckeditor.js');
             return true;
         } else {
             if (self::$settings->get('active_editor', 'tinymce') == 'sceditor') {
                 $doc = \GCore\Libs\Document::getInstance();
                 $doc->_('jquery');
                 $doc->addCssFile(\GCore\C::get('GCORE_FRONT_URL') . 'extensions/editors/assets/sceditor/themes/default.min.css');
                 $doc->addCssFile(\GCore\C::get('GCORE_FRONT_URL') . 'extensions/editors/assets/sceditor/jquery.sceditor.default.min.css');
                 $doc->addJsFile(\GCore\C::get('GCORE_FRONT_URL') . 'extensions/editors/assets/sceditor/jquery.sceditor.bbcode.min.js');
                 return true;
             }
         }
     }
 }
예제 #4
0
    function execute(&$form, $action_id)
    {
        $config = $form->actions_config[$action_id];
        $config = new \GCore\Libs\Parameter($config);
        $model_id = $config->get('model_id', 'Data');
        $model_id = empty($model_id) ? 'Data' : $model_id;
        if ($config->get('enabled', 0)) {
            if ($config->get('ndb_enable', 0)) {
                \GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('ndb_table_name', ''), 'dbo_config' => array('type' => $config->get('ndb_driver', 'mysql'), 'host' => $config->get('ndb_host', 'localhost'), 'name' => $config->get('ndb_database', ''), 'user' => $config->get('ndb_user', ''), 'pass' => $config->get('ndb_password', ''), 'prefix' => $config->get('ndb_prefix', 'jos_'))));
            } else {
                if (!$config->get('tablename', '')) {
                    return;
                }
                //\GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('tablename', '')));
                $class_code = '
					namespace GCore\\Models;
					if(!class_exists("\\GCore\\Models\\' . $model_id . '", false)){
						class ' . $model_id . ' extends \\GCore\\Libs\\Model {
							var $tablename = "' . $config->get('tablename', '') . '";
							
							function beforeSave(&$data, &$params, $mode){
								if($mode == "create" AND empty($data["uniq_id"])){
									$data["uniq_id"] = \\GCore\\Libs\\Str::rand();
								}
							}
						}
					}
				';
                eval($class_code);
            }
            $model_class = '\\GCore\\Models\\' . $model_id;
            if (!class_exists($model_class)) {
                $form->debug[$action_id][self::$title]['Queries'] = "Error creating the model class, please try a different model id.";
                return;
            }
            $data = $form->data;
            if ((bool) $config->get('save_under_modelid', 0) === true) {
                $data = $form->data[$model_id];
            }
            $user = \GCore\Libs\Base::getUser();
            $conditions = eval('?>' . $config->get('conditions', ''));
            $initial_queries = $model_class::getInstance()->dbo->log;
            if ((bool) $config->get('multi_save', 0) === true) {
                //$data['user_id'] = !empty($data['user_id']) ? $data['user_id'] : $user['id'];
                $model_class::getInstance()->saveAll($data, array('new' => (bool) $config->get('force_save', 0), 'conditions' => $conditions));
            } else {
                $data['user_id'] = !empty($data['user_id']) ? $data['user_id'] : $user['id'];
                $model_class::getInstance()->save($data, array('new' => (bool) $config->get('force_save', 0), 'conditions' => $conditions));
            }
            //insert the pkey value to data
            if ((bool) $config->get('save_under_modelid', 0) === true) {
                $form->data[$model_id][$model_class::getInstance()->pkey] = $model_class::getInstance()->id;
            } else {
                $form->data[$model_class::getInstance()->pkey] = $model_class::getInstance()->id;
            }
            $form->debug[$action_id][self::$title]['Queries'] = array_values(array_diff($model_class::getInstance()->dbo->log, $initial_queries));
        }
    }
예제 #5
0
파일: user.php 프로젝트: ejailesb/repo_empr
 function beforeDelete(&$conditions, $params = array())
 {
     parent::beforeDelete($conditions, $params);
     $ids = $this->get_ids_of_conditions($conditions);
     if (count(array_intersect($this->default_items, $ids)) > 0) {
         $session = \GCore\Libs\Base::getSession();
         $session->setFlash('error', l_('USERS_CANT_DELETE_SITE_OWNER'));
         return false;
     }
 }
예제 #6
0
 function __construct($area, $joption, $extension, $setup = null, $cont_vars = array())
 {
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'gcloader.php';
     if (phpversion('pdo') !== false and in_array('mysql', PDO::getAvailableDrivers())) {
         //good, we use PDO
         \GCore\Libs\Base::setConfig('db_adapter', 'joomla');
     } else {
         \GCore\Libs\Base::setConfig('db_adapter', 'joomla');
     }
     \GCore\C::set('EXTENSIONS_PATHS', array(dirname(__FILE__) . DS . 'admin' . DS . 'extensions' . DS => JPATH_SITE . DS . 'administrator' . DS . 'components' . DS, dirname(__FILE__) . DS . 'extensions' . DS => JPATH_SITE . DS . 'components' . DS));
     \GCore\C::set('EXTENSIONS_URLS', array(\JFactory::getURI()->root() . 'libraries/cegcore/admin/extensions/' => \JFactory::getURI()->root() . 'administrator/components/', \JFactory::getURI()->root() . 'libraries/cegcore/extensions/' => \JFactory::getURI()->root() . 'components/'));
     \GCore\C::set('EXTENSIONS_NAMES', array('chronomigrator' => 'com_chronomigrator', 'chronoforms' => 'com_chronoforms5', 'chronoconnectivity' => 'com_chronoconnectivity5', 'chronoforums' => 'com_chronoforums', 'chronolistings' => 'com_chronolistings', 'chronocommunity' => 'com_chronocommunity', 'chronosearch' => 'com_chronosearch', 'chronocontact' => 'com_chronocontact', $extension => 'com_' . $joption));
     //GCore\Libs\Url::$root_ext = array('components', 'com_'.$joption);
     \GCore\Bootstrap::initialize('joomla', array('component' => 'com_' . $joption, 'ext' => $extension));
     $tvout = strlen(\GCore\Libs\Request::data('tvout', null)) > 0 ? \GCore\Libs\Request::data('tvout') : '';
     $controller = \GCore\Libs\Request::data('cont', '');
     $action = \GCore\Libs\Request::data('act', '');
     if (is_callable($setup)) {
         $return_vars = $setup();
         if (!empty($return_vars)) {
             $cont_vars = array_merge($cont_vars, $return_vars);
         }
     }
     if (isset($cont_vars['controller'])) {
         $controller = $cont_vars['controller'];
     }
     if (isset($cont_vars['action'])) {
         $action = $cont_vars['action'];
     }
     $cont_vars['_app_thread'] = 'gcore';
     ob_start();
     echo \GCore\Libs\AppJ::call($area, $extension, $controller, $action, $cont_vars);
     $output = ob_get_clean();
     $output = \GCore\C::fix_urls($output);
     if ($tvout == 'ajax') {
         echo $output;
         $mainframe = \JFactory::getApplication();
         $mainframe->close();
     } else {
         ob_start();
         $toolbar = \GCore\Helpers\Module::render(array('type' => 'toolbar', 'site' => 'admin', 'params' => ''));
         $messages = \GCore\Libs\AppJ::getSystemMessages();
         echo \GCore\Libs\AppJ::getHeader();
         if ($toolbar) {
             echo $toolbar;
             echo '<div style="clear:both;"></div>';
         }
         echo $messages;
         //echo \GCore\Libs\AppJ::getHeader();
         $system_output = ob_get_clean();
         $system_output = \GCore\C::fix_urls($system_output);
         echo $system_output;
         echo $output;
     }
 }
예제 #7
0
 public static function __callStatic($name, $args)
 {
     $class_name = get_called_class();
     $class_id = \GCore\Libs\Str::uncamilize(\GCore\Libs\Base::getClassName($class_name));
     $class_id .= '_';
     if (method_exists(\GCore\Helpers\Theme::getInstance(), $class_id . $name)) {
         return call_user_func_array(array(\GCore\Helpers\Theme::getInstance(), $class_id . $name), $args);
     }
     if (method_exists($class_name, $class_id . $name)) {
         return call_user_func_array(array($class_name, $class_id . $name), $args);
     }
 }
예제 #8
0
 function index()
 {
     //apply updates
     $sql = file_get_contents(\GCore\C::ext_path('chronoforms', 'admin') . 'sql' . DS . 'install.chronoforms.sql');
     $queries = \GCore\Libs\Database::getInstance()->split_sql($sql);
     foreach ($queries as $query) {
         \GCore\Libs\Database::getInstance()->exec(\GCore\Libs\Database::getInstance()->_prefixTable($query));
     }
     $session = \GCore\Libs\Base::getSession();
     $session->setFlash('success', l_('CF_DB_TABLES_INSTALLED'));
     $this->redirect(r_('index.php?ext=chronoforms'));
 }
예제 #9
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     $session_ns = $config->get('namespace', '');
     $session_key = $config->get('key', '');
     if (empty($session_key)) {
         $session_key = $form->form['Form']['title'];
     }
     if (empty($session_ns)) {
         $session_ns = 'default';
     }
     $form->data = array_merge($form->data, $session->get('_chronoform_data_' . $session_key, array()));
     //clear the session if the clear option is set to yes
     if ((bool) $config->get('clear', 0) === true) {
         $session->clear('_chronoform_data_' . $session_key);
     }
 }
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     //extract questions
     $q_as = explode("\n", $config->get('questions', ''));
     $rand = rand(0, count($q_as) - 1);
     $choosen = explode("=", $q_as[$rand]);
     $answers = explode(',', trim($choosen[1]));
     foreach ($answers as $k => $answer) {
         $answers[$k] = strtolower($answer);
     }
     $session_key = $config->get('session_key', '');
     if (empty($session_key)) {
         $session_key = $form->form['Form']['title'];
     }
     $session->set('chrono_security_answers_' . $session_key, $answers);
     $form->form['Form']['content'] = str_replace('{chrono_security_question}', trim($choosen[0]), $form->form['Form']['content']);
 }
예제 #11
0
 function execute(&$form, $action_id)
 {
     $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     $session_key = $config->get('session_key', '');
     if (empty($session_key)) {
         $session_key = $form->form['Form']['title'];
     }
     if ($config->get('reset', 0)) {
         $session->set('_chronoforms_paging_data_' . $session_key, array());
         $session->set('_chronoforms_paging_files_' . $session_key, array());
     }
     $stored_data = $session->get('_chronoforms_paging_data_' . $session_key, array());
     $stored_files = $session->get('_chronoforms_paging_files_' . $session_key, array());
     $session->set('_chronoforms_paging_data_' . $session_key, $this->merge($stored_data, $form->data));
     $session->set('_chronoforms_paging_files_' . $session_key, array_merge($stored_files, $form->files));
     $form->data = $this->merge($stored_data, $form->data);
     $form->files = array_merge($session->get('_chronoforms_paging_files_' . $session_key, array()), $form->files);
 }
예제 #12
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     $limit = (int) $config->get('limit', 20);
     $form_title = $form->form['Form']['title'];
     //limit exists
     $last_submit = $session->get($form_title . '.submit_limit.limit', 0);
     //form has been submitted this session
     if (!empty($last_submit)) {
         if ($last_submit + $limit > time()) {
             $this->events['fail'] = 1;
             if ($config->get('message', '')) {
                 $session->setFlash('error', $config->get('message', ''));
             }
             return;
         }
     }
     $session->set($form_title . '.submit_limit.limit', time());
     //$this->events['good_submit'] = 1;
     return;
 }
예제 #13
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $session = \GCore\Libs\Base::getSession();
     $session_ns = $config->get('namespace', '');
     $session_key = $config->get('key', '');
     if (empty($session_key)) {
         $session_key = $form->form['Form']['title'];
     }
     if (empty($session_ns)) {
         $session_ns = 'default';
     }
     if ($session->has('_chronoform_data_' . $session_key)) {
         $stored = $session->get('_chronoform_data_' . $session_key, array());
         if (!empty($stored) and is_array($stored) and (bool) $config->get('merge', 0) === true) {
             $session->set('_chronoform_data_' . $session_key, array_merge($stored, $form->data));
         } else {
             $session->set('_chronoform_data_' . $session_key, $form->data);
         }
     } else {
         $session->set('_chronoform_data_' . $session_key, $form->data);
     }
 }
예제 #14
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $mainframe = \JFactory::getApplication();
     //set data
     $user = \GCore\Libs\Base::getUser();
     $article_data['created_by'] = $user['id'];
     $article_data['access'] = $config->get('access', 1);
     $article_data['created'] = date("Y-m-d H:i:s");
     $article_data['catid'] = $config->get('catid', '');
     $article_data['sectionid'] = $config->get('sectionid', 0);
     $article_data['state'] = $config->get('state', 0);
     $article_data['title'] = $form->data($config->get('title', ''));
     $article_data['fulltext'] = $form->data($config->get('fulltext', ''));
     $article_data['introtext'] = strlen($form->data($config->get('introtext', ''))) ? $form->data($config->get('introtext', '')) : '';
     //$article_data['created_by_alias'] = $form->data[$config->get('created_by_alias', '')];
     $article_data['language'] = '*';
     //alias
     $article_data['alias'] = \JFilterOutput::stringURLSafe($article_data['title']);
     //$article_data['id'] = null;
     \GCore\Libs\GModel::generateModel('CFJArticle', array('tablename' => '#__content'));
     \GCore\Models\CFJArticle::getInstance()->save($article_data);
 }
예제 #15
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $model_id = $config->get('model_id', 'Data');
     $model_id = empty($model_id) ? 'Data' : $model_id;
     if ($config->get('tablename', '')) {
         \GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('tablename', '')));
         $model_class = '\\GCore\\Models\\' . $model_id;
         $data = $form->data;
         if ((bool) $config->get('save_under_modelid', 0) === true) {
             $data = $form->data[$model_id];
         }
         $user = \GCore\Libs\Base::getUser();
         $data['user_id'] = $user['id'];
         $initial_queries = $model_class::getInstance()->dbo->log;
         if ((bool) $config->get('multi_save', 0) === true) {
             $model_class::getInstance()->saveAll($data);
         } else {
             $model_class::getInstance()->save($data);
         }
         $form->debug[$action_id][self::$title]['Queries'] = array_values(array_diff($model_class::getInstance()->dbo->log, $initial_queries));
     }
 }
예제 #16
0
    function execute(&$form, $action_id)
    {
        $config = $form->actions_config[$action_id];
        $config = new \GCore\Libs\Parameter($config);
        $session = \GCore\Libs\Base::getSession();
        //extract questions
        $field_name = \GCore\Libs\Str::rand();
        $session_key = $config->get('session_key', '');
        if (empty($session_key)) {
            $session_key = $form->form['Form']['title'];
        }
        $session->set('chrono_honeypot_' . $session_key, array('name' => $field_name, 'time' => time()));
        $field_code = \GCore\Helpers\Html::input($field_name, array('type' => 'hidden', 'value' => 1));
        if ($config->get('method', 'static') == 'static') {
            $form->form['Form']['content'] = $form->form['Form']['content'] . $field_code;
        } else {
            $doc = \GCore\Libs\Document::getInstance();
            $doc->addJsCode('
			jQuery(document).ready(function($){
				$("#chronoform-' . $form->form['Form']['title'] . '").append(\'' . $field_code . '\');
			});
			');
        }
    }
예제 #17
0
 public function getList($lang = array())
 {
     $dropdown = \GCore\Helpers\Html::input('limit', array('type' => 'dropdown', 'values' => $this->limit, 'class' => 'SS', 'onchange' => "jQuery(this).closest('form').submit();", 'options' => array(5 => 5, 10 => 10, 15 => 15, 20 => 20, 30 => 30, 50 => 50, 100 => 100, \GCore\Libs\Base::getConfig('max_list_limit', 1000) => self::l_('PAGINATOR_ALL', $lang))));
     //$text = sprintf(self::l_('PAGINATOR_SHOW_X_ENTRIES', $lang), $dropdown);
     $full = \GCore\Helpers\Html::container('div', $dropdown, array('class' => 'gcore-datatable-list'));
     return $full;
 }
예제 #18
0
파일: file.php 프로젝트: ejailesb/repo_empr
 function __construct($domain = 'gcore', $params = array('dir' => '', 'expiration' => 0))
 {
     $this->dir = empty($params['dir']) ? \GCore\C::get('GCORE_FRONT_PATH') . 'cache' . DS : $params['dir'];
     $this->expiration = !empty($params['expiration']) ? $params['expiration'] : \GCore\Libs\Base::getConfig('app_cache_expiry', 900);
     $this->domain = $domain;
 }
예제 #19
0
 public static function display($type = 0, $key = 'gcore_captcha')
 {
     @error_reporting(0);
     $alphanum = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghijkmnpqrstuvwxyz';
     $front_chars = substr(str_shuffle($alphanum), 0, 5);
     $back_chars = substr(str_shuffle($alphanum), 0, 7);
     $session = \GCore\Libs\Base::getSession();
     $session->set($key, md5(strtolower($front_chars)));
     header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Cache-Control: post-check=0, pre-check=0', false);
     header('Pragma: no-cache');
     header('Content-type: image/png');
     switch ($type) {
         case 1:
             $font = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'default.ttf';
             $image_size = imagettfbbox(20, 0, $font, 'X');
             $image_size = 5 * (abs($image_size[2] - $image_size[0]) + 7);
             $width = $image_size;
             $height = 40;
             $im = imagecreatetruecolor($width, $height);
             // Create some colors
             $white = imagecolorallocate($im, 255, 255, 255);
             $grey = imagecolorallocate($im, 128, 128, 128);
             $greylight = imagecolorallocate($im, 199, 199, 199);
             $black = imagecolorallocate($im, 0, 0, 0);
             //create the background image rect
             imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $white);
             // The text to draw
             $chars = array();
             $chars2 = array();
             for ($i = 0; $i < strlen($front_chars); $i++) {
                 $chars[] = $front_chars[$i];
             }
             for ($i = 0; $i < strlen($back_chars); $i++) {
                 $chars2[] = $back_chars[$i];
             }
             $square_count = 6;
             for ($i = 0; $i < $square_count; $i++) {
                 $cx = (int) rand(0, $width / 2);
                 $cy = (int) rand(0, $height);
                 $h = $cy + (int) rand(0, $height / 5);
                 $w = $cx + (int) rand($width / 3, $width);
                 imagefilledrectangle($im, $cx, $cy, $w, $h, $greylight);
             }
             $ellipse_count = 5;
             for ($i = 0; $i < $ellipse_count; $i++) {
                 $cx = (int) rand(-1 * ($width / 2), $width + $width / 2);
                 $cy = (int) rand(-1 * ($height / 2), $height + $height / 2);
                 $h = (int) rand($height / 2, 2 * $height);
                 $w = (int) rand($width / 2, 2 * $width);
                 imageellipse($im, $cx, $cy, $w, $h, $black);
             }
             $back_char_size = 20;
             $back_char_angle = 0;
             $back_char_x = 10;
             $back_char_y = 25;
             $bbox2 = array();
             $bbox2[0] = 0;
             $bbox2[2] = 0;
             foreach ($chars2 as $char2) {
                 $back_char_angle = rand(-20, 20);
                 $back_char_size = rand(15, 20);
                 $back_char_y = rand(0, 40);
                 imagettftext($im, $back_char_size, $back_char_angle, $back_char_x, $back_char_y, $greylight, $font, $char2);
                 $bbox2 = imagettfbbox($back_char_size, $back_char_angle, $font, $char2);
                 $back_char_x = $back_char_x + abs($bbox2[2] - $bbox2[0]) + 3;
             }
             $front_char_size = 20;
             $front_char_angle = 0;
             $front_char_x = 10;
             $front_char_y = 25;
             $bbox = array();
             $bbox[0] = 0;
             $bbox[2] = 0;
             // Add the text
             foreach ($chars as $char) {
                 $front_char_angle = rand(-20, 20);
                 //$front_char_size = rand(15, 20);
                 imagettftext($im, $front_char_size, $front_char_angle, $front_char_x, $front_char_y, $black, $font, $char);
                 $bbox = imagettfbbox($front_char_size, $front_char_angle, $font, $char);
                 $front_char_x = $front_char_x + abs($bbox[2] - $bbox[0]) + 3;
             }
             // Using imagepng() results in clearer text compared with imagejpeg()
             imagepng($im);
             imagedestroy($im);
             break;
         case 0:
         default:
             $image = imagecreatefrompng(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'background.png');
             $greylight = imagecolorallocate($image, 199, 199, 199);
             $black = imagecolorallocate($image, 0, 0, 0);
             imagestring($image, 5, 8, 14, $back_chars, $greylight);
             imagestring($image, 5, 5, 11, $front_chars, $black);
             imagepng($image);
             imagedestroy($image);
             break;
     }
     exit;
 }
 function validateinstall()
 {
     $domain = str_replace(array('http://', 'https://'), '', \GCore\Libs\Url::domain());
     $this->set('domain', $domain);
     if (!empty($this->data['license_key'])) {
         $session = \GCore\Libs\Base::getSession();
         $fields = '';
         $update_fld = 'validated';
         if ($this->data['pid'] == 18) {
             $update_fld = 'validated_paypal';
         }
         if ($this->data['pid'] == 7) {
             $update_fld = 'validated_authorize';
         }
         if ($this->data['pid'] == 31) {
             $update_fld = 'validated_2checkout';
         }
         //$postfields = array();
         unset($this->data['option']);
         unset($this->data['act']);
         foreach ($this->data as $key => $value) {
             $fields .= "{$key}=" . urlencode($value) . "&";
         }
         $target_url = 'http://www.chronoengine.com/index.php?option=com_chronocontact&task=extra&chronoformname=validateLicense';
         $output = '-';
         if (ini_get('allow_url_fopen')) {
             $output = file_get_contents($target_url . '&' . rtrim($fields, "& "));
         } else {
             if (function_exists('curl_version')) {
                 $ch = curl_init();
                 curl_setopt($ch, CURLOPT_URL, $target_url);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                 curl_setopt($ch, CURLOPT_TIMEOUT, 10);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
                 $output = curl_exec($ch);
                 curl_close($ch);
             }
         }
         if ($output == '-') {
             $session->setFlash('error', 'Validation error, Could not connect to the remote server, your host does not have neither the CURL nor the allow_url_fopen.');
             $this->redirect(r_('index.php?ext=chronoforms'));
         }
         $validstatus = $output;
         if ($validstatus == 'valid') {
             parent::_settings('chronoforms');
             $this->data['Chronoforms'][$update_fld] = 1;
             $result = parent::_save_settings('chronoforms');
             if ($result) {
                 $session->setFlash('success', 'Validated successfully.');
                 $this->redirect(r_('index.php?ext=chronoforms'));
             } else {
                 $session->setFlash('error', 'Validation error.');
             }
         } else {
             if ($validstatus == 'invalid') {
                 parent::_settings('chronoforms');
                 $this->data['Chronoforms'][$update_fld] = 0;
                 $result = parent::_save_settings('chronoforms');
                 $session->setFlash('error', 'Validation error, you have provided incorrect data.');
                 $this->redirect(r_('index.php?ext=chronoforms'));
             } else {
                 if (!empty($this->data['instantcode'])) {
                     $step1 = base64_decode(trim($this->data['instantcode']));
                     $step2 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), 0, 7), '', $step1);
                     $step3 = str_replace(substr(md5(str_replace('www.', '', strtolower($matches[2]))), -strlen(md5(str_replace('www.', '', strtolower($matches[2])))) + 7), '', $step2);
                     $step4 = str_replace(substr($this->data['license_key'], 0, 10), '', $step3);
                     $step5 = str_replace(substr($this->data['license_key'], -strlen($this->data['license_key']) + 10), '', $step4);
                     //echo (int)$step5;return;
                     //if((((int)$step5 + (24 * 60 * 60)) > strtotime(date('d-m-Y H:i:s')))||(((int)$step5 - (24 * 60 * 60)) < strtotime(date('d-m-Y H:i:s')))){
                     if ((int) $step5 < strtotime("now") + 24 * 60 * 60 and (int) $step5 > strtotime("now") - 24 * 60 * 60) {
                         parent::_settings('chronoforms');
                         $this->data['Chronoforms'][$update_fld] = 1;
                         $result = parent::_save_settings('chronoforms');
                         if ($result) {
                             $session->setFlash('success', 'Validated successfully.');
                             $this->redirect(r_('index.php?ext=chronoforms'));
                         } else {
                             $session->setFlash('error', 'Validation error.');
                         }
                     } else {
                         $session->setFlash('error', 'Validation error, Invalid instant code provided.');
                         $this->redirect(r_('index.php?ext=chronoforms'));
                     }
                 } else {
                     if (!empty($this->data['serial_number'])) {
                         $blocks = explode("-", trim($this->data['serial_number']));
                         $hash = md5($this->data['pid'] . $this->data['license_key'] . str_replace('www.', '', $domain) . $blocks[3]);
                         if (substr($hash, 0, 7) == $blocks[4]) {
                             parent::_settings('chronoforms');
                             $this->data['Chronoforms'][$update_fld] = 1;
                             $result = parent::_save_settings('chronoforms');
                             if ($result) {
                                 $session->setFlash('success', 'Validated successfully.');
                                 $this->redirect(r_('index.php?ext=chronoforms'));
                             } else {
                                 $session->setFlash('error', 'Validation error.');
                             }
                         } else {
                             $session->setFlash('error', 'Serial number invalid!');
                         }
                     }
                     $session->setFlash('error', 'Validation error, please try again using the Instant Code, or please contact us on www.chronoengine.com');
                     $this->redirect(r_('index.php?ext=chronoforms'));
                 }
             }
         }
     }
 }
예제 #21
0
    function dispatch($content_only = false)
    {
        Event::trigger('on_before_dispatch', $this);
        $session = Base::getSession();
        reset:
        //if no action set, set it to index
        if (strlen(trim($this->action)) == 0) {
            $this->action = 'index';
        }
        //set admin path
        $site = '';
        if ($this->site == 'admin') {
            $site = '\\Admin';
        }
        //load the extension class
        $controller = !empty($this->controller) ? '\\Controllers\\' . Str::camilize($this->controller) : '\\' . Str::camilize($this->extension);
        $extension = !empty($this->extension) ? '\\Extensions\\' . Str::camilize($this->extension) : '';
        $classname = '\\GCore' . $site . $extension . $controller;
        $this->tvout = strlen(Request::data('tvout', null)) > 0 ? Request::data('tvout') : $this->tvout;
        //set referer
        if (!$content_only) {
            if (!($this->controller == 'users' and ($this->action == 'login' or $this->action == 'logout' or $this->action == 'register')) and (!empty($this->extension) or !empty($this->controller)) and $this->tvout == 'index') {
                //$session->set('_referer', Url::current());
            } else {
                //$session->set('_referer', 'index.php');
            }
        }
        $G_User = $session->get('user', array());
        //check permissions
        /*
        $J_User = \JFactory::getUser();
        if(empty($J_User->groups) OR empty($G_User['groups']) OR (array_values($J_User->groups) !== $G_User['groups']) OR empty($G_User['inheritance'])){
        	$user_session = array();
        	$user_session['id'] = $J_User->id;
        	$user_session['name'] = $J_User->name;
        	$user_session['username'] = $J_User->username;
        	$user_session['email'] = $J_User->email;
        	$user_session['last_login'] = $J_User->lastvisitDate;
        	$user_session['logged_in'] = !$J_User->guest;
        	$user_session['guest'] = $J_User->guest;
        	$user_session['groups'] = empty($J_User->groups) ? array(1) : array_values($J_User->groups);
        	$user_session['inheritance'] = array();
        	if(!empty($J_User->groups)){
        		//sort groups
        		$groups = \GCore\Admin\Models\Group::getInstance()->find('all', array('order' => 'Group.parent_id ASC'));
        		if(!empty($groups)){
        			reloop:
        			foreach($groups as $group){
        				//if this group exists in the user's groups or its inheitance then add its parent_id
        				if(in_array($group['Group']['id'], $user_session['groups']) OR in_array($group['Group']['id'], $user_session['inheritance'])){
        					$user_session['inheritance'][] = $group['Group']['parent_id'];
        				}
        			}
        			//find the number of occurances of each group in the inheritane
        			$groups_counted = array_count_values($user_session['inheritance']);
        			//if the count of root parent (0 parent_id) is less than the count of user's groups then not all pathes have been found, reloop
        			if((count($user_session['groups']) AND !isset($groups_counted[0])) OR $groups_counted[0] < count($user_session['groups'])){
        				goto reloop;
        			}else{
        				$user_session['inheritance'] = array_unique($user_session['inheritance']);
        			}
        		}
        	}
        	if($session->get('user', array()) !== $user_session){
        		$session->clear('acos_permissions');
        	}
        	$session->set('user', array_merge($session->get('user', array()), $user_session));
        }
        */
        //set timezone
        date_default_timezone_set(get_option('timezone_string'));
        //site title
        \GCore\Libs\Base::setConfig('site_title', get_bloginfo('name'));
        /*if(!Authorize::authorized($classname, $this->action)){
        			if($content_only){
        				return;
        			}
        			$this->redirect(r_('index.php?cont=users&act=login'));
        		}*/
        //if the extension class not found or the action function not found then load an error
        if (!class_exists($classname) or !in_array($this->action, get_class_methods($classname)) and !in_array('__call', get_class_methods($classname)) or substr($this->action, 0, 1) == '_') {
            $this->controller = 'errors';
            $this->action = 'e404';
            //reset the controller
            //$classname = '\GCore\Controllers\Errors';
            $this->buffer = 'Page not found';
            \GCore\Libs\Env::e404();
            //we need the rendered content only
            if ($content_only) {
                return;
            }
        }
        //load language file
        if (!empty($extension)) {
            Lang::load($site . $extension);
        }
        //set theme
        $doc = Document::getInstance($this->site, $this->thread);
        $doc->theme = 'bootstrap3';
        //$theme = \GCore\Helpers\Theme::getInstance();
        //load class and run the action
        ${$classname} = new $classname($this->site, $this->thread);
        ob_start();
        $continue = ${$classname}->_initialize();
        //check and read cache
        if (!empty(${$classname}->cache)) {
            if (!is_array(${$classname}->cache)) {
                ${$classname}->cache = array();
            }
            if (empty(${$classname}->cache['time'])) {
                ${$classname}->cache['time'] = Base::getConfig('app_cache_expiry', 900);
            }
            if (empty(${$classname}->cache['title'])) {
                ${$classname}->cache['title'] = File::makeSafe($classname . '_' . $this->action);
            } else {
                ${$classname}->cache['title'] = File::makeSafe(${$classname}->cache['title']);
            }
            if (empty(${$classname}->cache['key'])) {
                ${$classname}->cache['key'] = 'cached_view';
            } else {
                ${$classname}->cache['key'] = 'cached_view_' . ${$classname}->cache['key'];
            }
            $cache = Cache::getInstance(${$classname}->cache['title'], array('expiration' => ${$classname}->cache['time']));
            $cached_view = $cache->get(${$classname}->cache['key']);
            $cached = false;
            if (!empty($cached_view)) {
                $cached = true;
                $continue = false;
                echo $cached_view;
            }
        }
        if ($continue !== false) {
            ${$classname}->{$this->action}();
            if ($this->reset === true) {
                $this->reset = false;
                goto reset;
            }
            //initialize and render view
            $view = new View();
            $view->initialize(${$classname});
            $view->renderView($this->action);
        }
        //get the action output buffer
        $this->buffer = ob_get_clean();
        //check and save cache
        if (!empty(${$classname}->cache) and !$cached) {
            $cache = Cache::getInstance(${$classname}->cache['title'], array('expiration' => ${$classname}->cache['time']));
            $cache->set(${$classname}->cache['key'], $this->buffer);
        }
        //finalize
        ob_start();
        ${$classname}->_finalize();
        $this->buffer .= ob_get_clean();
        //now load the theme files
        $theme = \GCore\Helpers\Theme::getInstance();
        $doc->_('gtabs');
        $doc->_('gsliders');
        $doc->_('gmodal');
        $doc->_('gdropdown');
        ob_start();
        ?>
		jQuery(document).ready(function($){
			$('[data-g-toggle="tab"]').closest('.nav').gtabs({
				'pane_selector':'.tab-pane',
				'tab_selector':'[data-g-toggle="tab"]',
			});
			$('[data-g-toggle="collapse"]').closest('.panel-group').gsliders({
				'pane_selector':'.panel-collapse',
				'tab_selector':'[data-g-toggle="collapse"]',
				'active_pane_class':'in',
			});
			
			$('[data-g-toggle="modal"]').on('click', function(e){
				e.preventDefault();
				$modal = $($(this).data('g-target'));
				$modal.gmodal({
					'close_selector' : '[data-g-dismiss="modal"]',
				});
				$modal.gmodal('open');
			});
			
			$('.gdropdown').gdropdown();
			$('[data-g-toggle="dropdown"]').on('click', function(e){
				e.preventDefault();
				$(this).parent().find('.gdropdown').gdropdown('toggle');
			});
		});
		<?php 
        $js = ob_get_clean();
        $doc->addJsCode($js);
        if ($this->tvout != 'ajax' and strpos($doc->theme, 'bootstrap3') !== false) {
            $this->buffer = '<div class="gbs3">' . $this->buffer . '</div>';
        }
        //Event::trigger('on_after_dispatch');
    }
예제 #22
0
파일: lists.php 프로젝트: BillVGN/PortalPRP
 function save()
 {
     $this->save_model = $this->pmodel;
     $result = parent::_save();
     if ($result) {
         if ($this->Request->get('save_act') == 'apply') {
             $this->redirect(r_('index.php?ext=chronoconnectivity&cont=lists&act=edit&ccname=' . $this->connection['Connection']['title'] . '&gcb=' . $this->pmodel->id));
         } else {
             $this->redirect(r_('index.php?ext=chronoconnectivity&cont=lists&act=index&ccname=' . $this->connection['Connection']['title']));
         }
     } else {
         $this->edit();
         $this->view = 'edit';
         $session = \GCore\Libs\Base::getSession();
         $session->setFlash('error', \GCore\Libs\Arr::flatten($this->pmodel->errors));
     }
 }
예제 #23
0
 public static function initialize($plathform = '', $params = array())
 {
     switch ($plathform) {
         default:
             //CONSTANTS
             \GCore\C::set('GCORE_FRONT_PATH', dirname(__FILE__) . DS);
             \GCore\C::set('GCORE_ADMIN_PATH', dirname(__FILE__) . DS . 'admin' . DS);
             //initialize language
             \GCore\Libs\Lang::initialize();
             //SET ERROR CONFIG
             if ((int) Libs\Base::getConfig('error_reporting') != 1) {
                 error_reporting((int) Libs\Base::getConfig('error_reporting'));
             }
             if ((bool) Libs\Base::getConfig('debug') === true) {
                 \GCore\Libs\Error::initialize();
             }
             //timezone
             date_default_timezone_set(Libs\Base::getConfig('timezone', 'UTC'));
             break;
     }
     if ($plathform == 'joomla') {
         $mainframe = \JFactory::getApplication();
         \GCore\Libs\Base::setConfig('db_host', $mainframe->getCfg('host'));
         $dbtype = $mainframe->getCfg('dbtype') == 'mysqli' ? 'mysql' : $mainframe->getCfg('dbtype');
         \GCore\Libs\Base::setConfig('db_type', $dbtype);
         \GCore\Libs\Base::setConfig('db_name', $mainframe->getCfg('db'));
         \GCore\Libs\Base::setConfig('db_user', $mainframe->getCfg('user'));
         \GCore\Libs\Base::setConfig('db_pass', $mainframe->getCfg('password'));
         \GCore\Libs\Base::setConfig('db_prefix', $mainframe->getCfg('dbprefix'));
         \GCore\C::set('GSITE_PLATFORM', 'joomla');
         \GCore\C::set('GCORE_FRONT_URL', \JFactory::getURI()->root() . 'libraries/cegcore/');
         \GCore\C::set('GCORE_ADMIN_URL', \JFactory::getURI()->root() . 'libraries/cegcore/admin/');
         \GCore\C::set('GCORE_ROOT_URL', \JFactory::getURI()->root());
         \GCore\C::set('GCORE_ROOT_PATH', dirname(dirname(dirname(__FILE__))) . DS);
         $lang = \JFactory::getLanguage();
         \GCore\Libs\Base::setConfig('site_language', $lang->getTag());
     } else {
         if ($plathform == 'wordpress') {
             global $wpdb;
             \GCore\Libs\Base::setConfig('db_host', DB_HOST);
             $dbtype = 'mysql';
             \GCore\Libs\Base::setConfig('db_type', $dbtype);
             \GCore\Libs\Base::setConfig('db_name', DB_NAME);
             \GCore\Libs\Base::setConfig('db_user', DB_USER);
             \GCore\Libs\Base::setConfig('db_pass', DB_PASSWORD);
             \GCore\Libs\Base::setConfig('db_prefix', $wpdb->prefix);
             \GCore\C::set('GSITE_PLATFORM', 'wordpress');
             \GCore\C::set('GCORE_FRONT_URL', plugins_url() . '/' . $params['component'] . '/cegcore/');
             \GCore\C::set('GCORE_ADMIN_URL', plugins_url() . '/' . $params['component'] . '/cegcore/admin/');
             \GCore\C::set('GCORE_ROOT_URL', site_url() . '/');
             \GCore\C::set('GCORE_ROOT_PATH', dirname(dirname(dirname(__FILE__))) . DS);
             \GCore\Libs\Base::setConfig('site_language', get_bloginfo('language'));
             //change the default page parameter string because WP uses the param "page"
             \GCore\Libs\Base::setConfig('page_url_param_name', 'page_num');
             if (function_exists('wp_magic_quotes')) {
                 $stripslashes_wp = function (&$value) {
                     $value = stripslashes($value);
                 };
                 array_walk_recursive($_GET, $stripslashes_wp);
                 array_walk_recursive($_POST, $stripslashes_wp);
                 array_walk_recursive($_COOKIE, $stripslashes_wp);
                 array_walk_recursive($_REQUEST, $stripslashes_wp);
             }
         } else {
             \GCore\C::set('GSITE_PLATFORM', '');
             \GCore\C::set('GCORE_FRONT_URL', \GCore\Libs\Url::root());
             \GCore\C::set('GCORE_ADMIN_URL', \GCore\Libs\Url::root() . 'admin/');
             \GCore\C::set('GCORE_ROOT_URL', \GCore\C::get('GCORE_FRONT_URL'));
             \GCore\C::set('GCORE_ROOT_PATH', dirname(__FILE__) . DS);
         }
     }
     \GCore\C::set('GSITE_PATH', \GCore\C::get('GCORE_' . strtoupper(GCORE_SITE) . '_PATH'));
     \GCore\C::set('GSITE_URL', \GCore\C::get('GCORE_' . strtoupper(GCORE_SITE) . '_URL'));
 }
예제 #24
0
 function _paginate()
 {
     $model_class = !empty($this->paginate_model) ? $this->paginate_model : null;
     if (empty($model_class)) {
         $alias = $this->get_main_model();
         if (!empty($alias)) {
             $model_class = $this->{$alias};
         } else {
             return;
         }
     }
     $prefix = '';
     if (!empty($this->paginate_prefix)) {
         $prefix = '.' . $this->paginate_prefix;
     }
     //check if we should process pagination
     if (!empty($model_class) and in_array('\\GCore\\Helpers\\Paginator', $this->helpers) or in_array('\\GCore\\Helpers\\Paginator', array_keys($this->helpers))) {
         $session = Base::getSession();
         $k = array_search('\\GCore\\Helpers\\Paginator', $this->helpers);
         if ($k !== false) {
             unset($this->helpers[$k]);
         }
         $page = Request::data(\GCore\Libs\Base::getConfig('page_url_param_name', 'page'), $session->get(get_class($this) . $prefix . '.' . $model_class->alias . '.page', 1));
         $page = $page < 1 ? 1 : $page;
         $active_limit = !empty($model_class->page_limit) ? $model_class->page_limit : Base::getConfig('list_limit', 30);
         $limit = Request::data('limit', $session->get(get_class($this) . $prefix . '.' . $model_class->alias . '.limit', $active_limit));
         if ($limit == 0 or $limit > Base::getConfig('max_list_limit', 1000)) {
             $limit = Base::getConfig('max_list_limit', 1000);
         }
         if (!empty($model_class->limit)) {
             $limit = $model_class->limit;
         }
         if (!empty($model_class->page)) {
             $page = $model_class->page;
         }
         $offset = ($page - 1) * (int) $limit;
         $total = !empty($this->paginate_total) ? $this->paginate_total : $model_class->find('count', array('cache' => true));
         $bad_page = false;
         if ($offset >= $total) {
             //$page = ceil($total/$limit);
             $bad_page = true;
             $page = ceil($total / $limit);
             $offset = $limit * ($page - 1);
         }
         $page = $page < 1 ? 1 : $page;
         $offset = $offset < 0 ? 0 : $offset;
         $this->helpers['\\GCore\\Helpers\\Paginator']['limit'] = $limit;
         $this->helpers['\\GCore\\Helpers\\Paginator']['page'] = $page;
         $this->helpers['\\GCore\\Helpers\\Paginator']['offset'] = $offset;
         $this->helpers['\\GCore\\Helpers\\Paginator']['page_param'] = \GCore\Libs\Base::getConfig('page_url_param_name', 'page');
         if (!$bad_page) {
             $session->set(get_class($this) . $prefix . '.' . $model_class->alias . '.page', $page);
         }
         $session->set(get_class($this) . $prefix . '.' . $model_class->alias . '.limit', $limit);
         $this->helpers['\\GCore\\Helpers\\Paginator']['total'] = $total;
         //page (limit and offset) should be set after the count query
         $model_class->page = $page;
         $model_class->page_limit = $limit;
     }
 }
예제 #25
0
    function execute(&$form, $action_id)
    {
        $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
        $config = new \GCore\Libs\Parameter($config);
        $doc = \GCore\Libs\Document::getInstance();
        //$doc->_('forms');
        //check fields validation
        /*
        if(!empty($form->form['Form']['extras']['fields'])){
        	$validations = array();
        	foreach($form->form['Form']['extras']['fields'] as $k => $field){
        		if(!empty($field['validation'])){
        			foreach($field['validation'] as $rule => $rule_data){
        				$validations[$rule][] = $field['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':');
        			}
        		}
        		if(!empty($field['inputs'])){
        			foreach($field['inputs'] as $fn => $field_input){
        				if(!empty($field_input['validation'])){
        					foreach($field_input['validation'] as $rule => $rule_data){
        						$validations[$rule][] = $field_input['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':');
        					}
        				}
        			}
        		}
        	}
        	foreach($validations as $rule => &$fields){
        		$fields = implode("\n", $fields);
        	}
        	$form->execute('client_validation', array('rules' => $validations));
        }
        */
        $theme = '';
        if ($form->params->get('theme', 'bootstrap3') == 'bootstrap3') {
            $theme = 'bootstrap3';
        } else {
            if ($form->params->get('theme', 'bootstrap3') == 'semantic1') {
                $theme = 'semantic1';
            } else {
                if ($form->params->get('theme', 'bootstrap3') == 'gcoreui') {
                    $theme = 'gcoreui';
                } else {
                    if ($form->params->get('theme', 'bootstrap3') == 'none') {
                        $theme = 'none';
                    }
                }
            }
        }
        $doc->theme = $theme;
        \GCore\Helpers\Theme::getInstance();
        if ($form->params->get('tight_layout', 0)) {
            $doc->addCssCode('
				.gbs3 .gcore-form-row{margin-bottom:5px;}
				.gcore-form-row .gcore-line-td{margin:0;}
			');
        }
        //check fields events
        if (!empty($form->form['Form']['extras']['fields'])) {
            $events_codes = array();
            $events_codes[] = 'jQuery(document).ready(function($){';
            foreach ($form->form['Form']['extras']['fields'] as $k => $field) {
                if (!empty($field['id']) and !empty($field['events'])) {
                    if ($field['type'] == 'dropdown') {
                        $change_event = 'change';
                    } else {
                        $change_event = 'click';
                    }
                    $_f = '$("[name=\'' . $field['name'] . '\']").on("' . $change_event . '", function(){';
                    $_l = '});';
                    $_m = array();
                    foreach ($field['events'] as $k => $event_data) {
                        if (strlen($event_data['action']) and strlen($event_data['target'])) {
                            $_m[] = $this->create_event($field, $event_data, $form);
                        }
                    }
                    if (!empty($_m)) {
                        $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l;
                    }
                }
                if (!empty($field['inputs'])) {
                    foreach ($field['inputs'] as $fn => $field_input) {
                        if (!empty($field_input['id']) and !empty($field_input['events'])) {
                            if ($field_input['type'] == 'dropdown') {
                                $change_event = 'change';
                            } else {
                                $change_event = 'click';
                            }
                            $_f = '$("[name=\'' . $field_input['name'] . '\']").on("' . $change_event . '", function(){';
                            $_l = '});';
                            $_m = array();
                            foreach ($field_input['events'] as $k => $event_data) {
                                if (strlen($event_data['action']) and strlen($event_data['target'])) {
                                    $_m[] = $this->create_event($field_input, $event_data, $form);
                                }
                            }
                            if (!empty($_m)) {
                                $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l;
                            }
                        }
                    }
                }
            }
            $events_codes[] = '});';
            if ((bool) $form->params->get('jquery', 1) === true) {
                $doc->_('jquery');
            }
            $form->execute('js', array('content' => implode("\n", $events_codes)));
        }
        ob_start();
        eval('?>' . $form->form['Form']['content']);
        $output = ob_get_clean();
        //select the page to display
        $form_pages = explode('<!--_CHRONOFORMS_PAGE_BREAK_-->', $output);
        $active_page_index = (int) $config->get('page', 1) - 1;
        $output = $form_pages[$active_page_index];
        //get current url
        $current_url = \GCore\Libs\Url::current();
        if ((bool) $config->get('relative_url', 1) === false) {
            $current_url = r_('index.php?ext=chronoforms');
        }
        //generate <form tag
        $form_tag = '<form';
        $form_action = strlen($config->get('action_url', '')) > 0 ? $config->get('action_url', '') : \GCore\Libs\Url::buildQuery($current_url, array('chronoform' => $form->form['Form']['title'], 'event' => $config->get('submit_event', 'submit')));
        $form_tag .= ' action="' . r_($form_action) . '"';
        //get method
        $form_method = $config->get('form_method', 'post');
        if ($config->get('form_method', 'post') == 'file') {
            $form_tag .= ' enctype="multipart/form-data"';
            $form_method = 'post';
        }
        $form_tag .= ' method="' . $form_method . '"';
        $form_tag .= ' name="' . $form->form['Form']['title'] . '"';
        $form_id = 'chronoform-' . $form->form['Form']['title'];
        $form_tag .= ' id="' . $form_id . '"';
        $form_tag .= ' class="' . $config->get('form_class', 'chronoform') . ($theme == 'bootstrap3' ? ' form-horizontal' : '') . '"';
        if ($config->get('form_tag_attach', '')) {
            $form_tag .= $config->get('form_tag_attach', '');
        }
        $form_tag .= '>';
        if (empty($theme)) {
            $doc->_('forms');
        }
        /*
        if($theme == 'bootstrap3'){
        	$doc->_('jquery');
        	$doc->_('bootstrap');
        	//echo '<div class="gcore chronoform-container">';
        }
        */
        if (strpos($output, 'data-wysiwyg="1"') !== false) {
            $doc->_('jquery');
            $doc->_('editor');
            $doc->addJsCode('jQuery(document).ready(function($){ $(\'*[data-wysiwyg="1"]\').each(function(){ tinymce.init({"selector":"#"+$(this).attr("id")}); }); });');
        }
        if (strpos($output, 'validate[') !== false) {
            $doc->_('jquery');
            $doc->_('gvalidation');
            $doc->addJsCode('jQuery(document).ready(function($){ $("#chronoform-' . $form->form['Form']['title'] . '").gvalidate(); });');
            if ($config->get('required_labels_identify', 1)) {
                if ($form->params->get('theme', 'bootstrap3') == 'bootstrap3') {
                    $required_icon = '<i class=\'fa fa-asterisk\' style=\'color:#ff0000; font-size:9px; vertical-align:top;\'></i>';
                } else {
                    $required_icon = '<span style=\'color:#ff0000; font-size:12px; vertical-align:top;\'>*</span>';
                }
                $doc->addJsCode('jQuery(document).ready(function($){
					$("#chronoform-' . $form->form['Form']['title'] . '").find(":input[class*=validate]").each(function(){
						if($(this).attr("class").indexOf("required") >= 0 || $(this).attr("class").indexOf("group") >= 0){
							if($(this).closest(".gcore-subinput-container").length > 0){
								var required_parent = $(this).closest(".gcore-subinput-container");
							}else if($(this).closest(".gcore-form-row").length > 0){
								var required_parent = $(this).closest(".gcore-form-row");
							}
							if(required_parent.length > 0){
								var required_label = required_parent.find("label");
								if(required_label.length > 0 && !required_label.first().hasClass("required_label")){
									required_label.first().addClass("required_label");
									required_label.first().html(required_label.first().html() + " ' . $required_icon . '");
								}
							}
						}
					});
				});');
            }
        }
        if (strpos($output, 'data-tooltip') !== false) {
            $doc->_('jquery');
            $doc->_('gtooltip');
            $doc->addJsCode('jQuery(document).ready(function($){
				$("#chronoform-' . $form->form['Form']['title'] . '").find(":input").each(function(){
					if($(this).data("tooltip") && $(this).closest(".gcore-input").length > 0 && $(this).closest(".gcore-input").next(".input-tooltip").length < 1){
						var $tip = $(\'<i class="fa fa-exclamation-circle input-tooltip" style="float:left; padding:7px 0px 0px 7px;"></i>\').attr("title", $(this).data("tooltip"));
						$(this).closest(".gcore-input").after($tip);
					}
				});
				$("#chronoform-' . $form->form['Form']['title'] . ' .input-tooltip").gtooltip("hover");
			});');
        }
        if (strpos($output, 'data-load-state') !== false) {
            $doc->_('jquery');
            $doc->addJsCode('jQuery(document).ready(function($){
				$("#chronoform-' . $form->form['Form']['title'] . '").find(\':input[data-load-state="disabled"]\').prop("disabled", true);
				$("#chronoform-' . $form->form['Form']['title'] . '").find(\':input[data-load-state="hidden"]\').css("display", "none");
				$("#chronoform-' . $form->form['Form']['title'] . '").find(\':input[data-load-state="hidden_parent"]\').each(function(){
					if($(this).closest(".gcore-subinput-container").length > 0){
						$(this).closest(".gcore-subinput-container").css("display", "none");
					}else if($(this).closest(".gcore-form-row").length > 0){
						$(this).closest(".gcore-form-row").css("display", "none");
					}
				});
			});');
        }
        if (strpos($output, 'data-inputmask=') !== false) {
            $doc->_('jquery');
            $doc->_('jquery.inputmask');
            $doc->addJsCode('jQuery(document).ready(function($){ $(":input").inputmask(); });');
        }
        if (strpos($output, 'data-gdatetimepicker') !== false) {
            $doc->_('jquery');
            $doc->_('gdatetimepicker');
            $doc->addJsCode('jQuery(document).ready(function($){ $(\'*[data-gdatetimepicker="1"]\').gdatetimepicker(); });');
        }
        if ((bool) $config->get('ajax_submit', 0) === true) {
            $doc->_('jquery');
            $ajax_url = \GCore\Libs\Url::buildQuery($form_action, array('tvout' => 'ajax'));
            $doc->addJsCode('
				jQuery(document).ready(function($){
					function chrono_ajax_submit(){
						$("#' . $form_id . '").submit(function(){
							var overlay = $("<div/>").css({
								"position": "fixed",
								"top": "0",
								"left": "0",
								"width": "100%",
								"height": "100%",
								"background-color": "#000",
								"filter": "alpha(opacity=50)",
								"-moz-opacity": "0.5",
								"-khtml-opacity": "0.5",
								"opacity": "0.5",
								"z-index": "10000",
								"background-image":"url(\\"' . \GCore\Helpers\Assets::image('loading-small.gif') . '\\")",
								"background-position":"center center",
								"background-repeat":"no-repeat",
							});
							$("#' . $form_id . '").append(overlay);
							$.ajax({
								"type" : "POST",
								"url" : "' . r_($ajax_url) . '",
								"data" : $("#' . $form_id . '").serialize(),
								"success" : function(res){
									$("#' . $form_id . '").replaceWith(res);
									chrono_ajax_submit();
								},
							});
							return false;
						});
					}
					chrono_ajax_submit();
				});
			');
        }
        echo $form_tag;
        //if ajax then display system messages inside the form
        if ((bool) $config->get('ajax_submit', 0) === true) {
            $doc = \GCore\Libs\Document::getInstance();
            $doc->addCssFile('system_messages');
            $session = \GCore\Libs\Base::getSession();
            $types = $session->getFlash();
            echo \GCore\Helpers\Message::render($types);
        }
        //add fields values
        $output = \GCore\Helpers\DataLoader::load($output, $form->data);
        //show output
        echo $output;
        echo '</form>';
        /*if($theme == 'bootstrap3'){
        			echo '</div>';
        		}*/
    }
예제 #26
0
    function execute(&$form, $action_id)
    {
        $config = !empty($form->actions_config[$action_id]) ? $form->actions_config[$action_id] : array();
        $config = new \GCore\Libs\Parameter($config);
        $doc = \GCore\Libs\Document::getInstance();
        $form_id = 'chronoform-' . $form->form['Form']['title'];
        //$doc->_('forms');
        //check fields validation
        /*
        if(!empty($form->form['Form']['extras']['fields'])){
        	$validations = array();
        	foreach($form->form['Form']['extras']['fields'] as $k => $field){
        		if(!empty($field['validation'])){
        			foreach($field['validation'] as $rule => $rule_data){
        				$validations[$rule][] = $field['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':');
        			}
        		}
        		if(!empty($field['inputs'])){
        			foreach($field['inputs'] as $fn => $field_input){
        				if(!empty($field_input['validation'])){
        					foreach($field_input['validation'] as $rule => $rule_data){
        						$validations[$rule][] = $field_input['name'].(strlen(trim($rule_data)) > 0 ? ':'.$rule_data : ':');
        					}
        				}
        			}
        		}
        	}
        	foreach($validations as $rule => &$fields){
        		$fields = implode("\n", $fields);
        	}
        	$form->execute('client_validation', array('rules' => $validations));
        }
        */
        $theme = $form->params->get('theme', 'bootstrap3');
        /*if($form->params->get('theme', 'bootstrap3') == 'bootstrap3'){
        			$theme = 'bootstrap3';
        		}else if($form->params->get('theme', 'bootstrap3') == 'bootstrap3_pure'){
        			$theme = 'bootstrap3_pure';
        		}else if($form->params->get('theme', 'bootstrap3') == 'semantic1'){
        			$theme = 'semantic1';
        		}else if($form->params->get('theme', 'bootstrap3') == 'gcoreui'){
        			$theme = 'gcoreui';
        		}else if($form->params->get('theme', 'bootstrap3') == 'none'){
        			$theme = 'none';
        		}*/
        $doc->theme = $theme;
        \GCore\Helpers\Theme::getInstance();
        if ($form->params->get('tight_layout', 0)) {
            $doc->addCssCode('
				.gbs3 .gcore-form-row{margin-bottom:5px;}
				.gcore-form-row .gcore-line-td{margin:0;}
			');
        }
        if ($form->params->get('rtl_support', 0)) {
            $doc->addCssCode('
				#' . $form_id . '.chronoform{direction:rtl;}
			');
            if ($form->params->get('theme', 'bootstrap3') == 'bootstrap3') {
                $doc->addCssCode('
					#' . $form_id . ' .gcore-label-left{
						float:right !important;
						min-width:160px;
						max-width:160px;
						padding-left:7px;
						text-align:right !important;
					}
					#' . $form_id . ' .gcore-label-top{
						display:block;
						text-align:right !important;
						float:none !important;
						width:auto !important;
					}
					#' . $form_id . ' .gcore-form-row > .gcore-label-checkbox{
						float:right !important;
						min-width:160px;
						padding-right:7px;
						padding-top: 1px !important;
						text-align:right !important;
					}
					#' . $form_id . ' .gcore-subinput-container{
						float:right;
					}
					#' . $form_id . ' .gcore-multiple-column .gcore-checkbox-item, .gcore-multiple-column .gcore-radio-item{
						float: right;
					}
					#' . $form_id . ' .gcore-multiple-column .gcore-checkbox-item:not(:first-child), .gcore-multiple-column .gcore-radio-item:not(:first-child){
						padding-right: 5px;
					}
				');
            }
            if ($form->params->get('theme', 'bootstrap3') == 'gcoreui') {
                $doc->addCssCode('
					#' . $form_id . ' .gcore-label-left {
						min-width: 150px !important;
						max-width: 150px !important;
						display: inline-block;
						white-space: normal;
						float: right !important;
						padding: 1px;
						padding-right: 10px !important;
						font-weight: bold;
					}
					#' . $form_id . ' .gcore-input-container {
						float: right;
						overflow: auto;
						display: inline-block;
						white-space: normal;
					}
					#' . $form_id . ' .gcore-line-tr .gcore-input{
						float:right;
					}
					#' . $form_id . ' .gcore-subinput-container {
						margin-bottom: 3px;
						overflow: auto;
						float: right;
					}
					#' . $form_id . ' .gcore-subinput-container:not(:first-child) {
						padding-right: 4px;
					}
					#' . $form_id . ' .gcore-subinput-container-wide {
						display: inline-block;
						margin: 0px 3px 3px 0px;
						float: right;
						overflow: auto;
					}
					#' . $form_id . ' .gcore-radio-item,
					#' . $form_id . ' .gcore-checkbox-item {
						float: right;
						margin: 0px 6px 6px 0px;
						white-space: nowrap;
					}
					#' . $form_id . ' .gcore-single-column .gcore-radio-item,
					#' . $form_id . ' .gcore-single-column .gcore-checkbox-item {
						clear: right;
					}
				');
            }
        }
        if ($form->params->get('labels_right_aligned', 0)) {
            $doc->addCssCode('
				#' . $form_id . ' .gcore-label-left{
					text-align:' . ($form->params->get('rtl_support', 0) ? 'left' : 'right') . ' !important;
				}
			');
        }
        if ($form->params->get('labels_auto_width', 0)) {
            $doc->addCssCode('
				#' . $form_id . ' .gcore-label-left{
					min-width: 0px !important;
					max-width: none !important;
					width: auto !important;
				}
			');
        }
        if ($form->params->get('js_validation_language', '') == '') {
            $lang = strtolower(\GCore\Libs\Base::getConfig('site_language'));
            $js_lang_tag = explode('-', $lang);
            $form->params->set('js_validation_language', $js_lang_tag[0]);
        }
        $events_codes = array();
        //check fields events
        if (!empty($form->form['Form']['extras']['fields'])) {
            //$events_codes = array();
            $pageload_events_codes = array();
            //$events_codes[] = 'jQuery(document).ready(function($){';
            $events_codes[] = 'function chronoforms_fields_events(){';
            foreach ($form->form['Form']['extras']['fields'] as $k => $field) {
                if (!empty($field['id']) and !empty($field['events'])) {
                    if ($field['type'] == 'dropdown') {
                        $change_event = 'change';
                    } else {
                        $change_event = 'click';
                    }
                    $_f = '$("[name=\'' . $field['name'] . '\']").on("' . $change_event . '", function(){';
                    $_l = '});';
                    $_m = array();
                    foreach ($field['events'] as $k => $event_data) {
                        if (strlen($event_data['action']) and strlen($event_data['target'])) {
                            $_m[] = $this->create_event($field, $event_data, $form);
                        }
                    }
                    if (!empty($_m)) {
                        $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l;
                        $pageload_events_codes[] = implode("\n", $_m);
                    }
                }
                if (!empty($field['inputs'])) {
                    foreach ($field['inputs'] as $fn => $field_input) {
                        if (!empty($field_input['id']) and !empty($field_input['events'])) {
                            if ($field_input['type'] == 'dropdown') {
                                $change_event = 'change';
                            } else {
                                $change_event = 'click';
                            }
                            $_f = '$("[name=\'' . $field_input['name'] . '\']").on("' . $change_event . '", function(){';
                            $_l = '});';
                            $_m = array();
                            foreach ($field_input['events'] as $k => $event_data) {
                                if (strlen($event_data['action']) and strlen($event_data['target'])) {
                                    $_m[] = $this->create_event($field_input, $event_data, $form);
                                }
                            }
                            if (!empty($_m)) {
                                $events_codes[] = $_f . "\n" . implode("\n", $_m) . "\n" . $_l;
                                $pageload_events_codes[] = implode("\n", $_m);
                            }
                        }
                    }
                }
            }
            //check new fields events
            if (!empty($form->form['Form']['extras']['jsevents'])) {
                $jsevents_codes = array();
                foreach ($form->form['Form']['extras']['jsevents'] as $k => $jsevent_info) {
                    if (empty($jsevent_info['source'])) {
                        continue;
                    }
                    //$source = $this->get_field_selector($jsevent_info['source'], $form);
                    $target = !empty($jsevent_info['target']) ? $this->get_field_selector($jsevent_info['target'], $form) : '';
                    $event_trigger = $this->get_event_trigger($jsevent_info, $form);
                    $type = $jsevent_info['type'];
                    $jsevent_class = '\\GCore\\Admin\\Extensions\\Chronoforms\\Events\\' . \GCore\Libs\Str::camilize($type) . '\\' . \GCore\Libs\Str::camilize($type);
                    $jsevents_codes[] = str_replace('__FUNCTION__', $jsevent_class::output($target, $jsevent_info, $form), $event_trigger);
                }
                $events_codes = array_merge($events_codes, $jsevents_codes);
            }
            $events_codes[] = '}';
            $events_codes[] = 'chronoforms_fields_events();';
            $events_codes[] = 'function chronoforms_pageload_fields_events(){';
            $events_codes[] = implode("\n", $pageload_events_codes);
            $events_codes[] = '}';
            $events_codes[] = 'chronoforms_pageload_fields_events();';
            //$form->execute('js', array('content' => implode("\n", $events_codes)));
        }
        ob_start();
        eval('?>' . $form->form['Form']['content']);
        $output = ob_get_clean();
        $form_content = $output;
        //select the page to display
        $form_pages = explode('<!--_CHRONOFORMS_PAGE_BREAK_-->', $output);
        $active_page_index = (int) $config->get('page', 1) - 1;
        $output = $form_pages[$active_page_index];
        //get current url
        $current_url = \GCore\Libs\Url::current();
        if ((bool) $config->get('relative_url', 1) === false) {
            $current_url = r_('index.php?ext=chronoforms');
        }
        //generate <form tag
        $form_tag = '<form';
        $form_action = strlen($config->get('action_url', '')) > 0 ? $config->get('action_url', '') : \GCore\Libs\Url::buildQuery($current_url, array('chronoform' => $form->form['Form']['title'], 'event' => $config->get('submit_event', 'submit')));
        $form_tag .= ' action="' . r_($form_action, (bool) $config->get('xhtml_url', 0)) . '"';
        //get method
        $form_method = $config->get('form_method', 'post');
        if ($config->get('form_method', 'post') == 'file') {
            $form_tag .= ' enctype="multipart/form-data"';
            $form_method = 'post';
        }
        $form_tag .= ' method="' . $form_method . '"';
        $form_tag .= ' name="' . $form->form['Form']['title'] . '"';
        //$form_id = 'chronoform-'.$form->form['Form']['title'];
        $form_tag .= ' id="' . $form_id . '"';
        $form_tag .= ' class="' . $config->get('form_class', 'chronoform') . ($theme == 'bootstrap3' ? ' form-horizontal' : '') . '"';
        if ($config->get('form_tag_attach', '')) {
            $form_tag .= ' ' . trim($config->get('form_tag_attach', ''));
        }
        $form_tag .= '>';
        if (empty($theme)) {
            $doc->_('forms');
        }
        /*
        if($theme == 'bootstrap3'){
        	$doc->_('jquery');
        	$doc->_('bootstrap');
        	//echo '<div class="gcore chronoform-container">';
        }
        */
        $js_scripts = array();
        if (strpos($output, 'data-wysiwyg="1"') !== false) {
            $doc->_('jquery');
            $doc->_('editor');
            $js_scripts[] = '$(\'*[data-wysiwyg="1"]\').each(function(){ tinymce.init({"selector":"#"+$(this).attr("id")}); });';
        }
        if (strpos($form_content, 'validate[') !== false) {
            $doc->_('jquery');
            $doc->_('gtooltip');
            $doc->_('gvalidation', array('lang' => $form->params->get('js_validation_language', 'en')));
            $js_scripts[] = '$("#' . $form_id . '").gvalidate();';
            $js_scripts[] = '
				$("#' . $form_id . '").find(":input").on("invalid.gvalidation", function(){
					var field = $(this);
					if(field.is(":hidden")){
						if(field.closest(".tab-pane").length > 0){
							var tab_id = field.closest(".tab-pane").attr("id");
							$(\'a[href="#\'+tab_id+\'"]\').closest(".nav").gtabs("get").show($(\'a[href="#\'+tab_id+\'"]\'));
						}
						if(field.closest(".panel-collapse").length > 0){
							var slider_id = field.closest(".panel-collapse").attr("id");
							$(\'a[href="#\'+slider_id+\'"]\').closest(".panel-group").gsliders("get").show($(\'a[href="#\'+slider_id+\'"]\'));
						}
					}
					if(field.data("wysiwyg") == "1"){
						field.data("gvalidation-target", field.parent());
					}
				});
				$("#' . $form_id . '").on("success.gvalidation", function(e){
					if($("#' . $form_id . '").data("gvalidate_success")){
						var gvalidate_success = $("#' . $form_id . '").data("gvalidate_success");
						if(gvalidate_success in window){
							window[gvalidate_success](e, $("#' . $form_id . '"));
						}
					}
				});
				$("#' . $form_id . '").on("fail.gvalidation", function(e){
					if($("#' . $form_id . '").data("gvalidate_fail")){
						var gvalidate_fail = $("#' . $form_id . '").data("gvalidate_fail");
						if(gvalidate_fail in window){
							window[gvalidate_fail](e, $("#' . $form_id . '"));
						}
					}
				});
			';
            if ($config->get('required_labels_identify', 1)) {
                if (strpos($form->params->get('theme', 'bootstrap3'), 'bootstrap3') !== false) {
                    $required_icon = '<i class=\'fa fa-asterisk\' style=\'color:#ff0000; font-size:9px; vertical-align:top;\'></i>';
                } else {
                    $required_icon = '<span style=\'color:#ff0000; font-size:12px; vertical-align:top;\'>*</span>';
                }
                $js_scripts[] = '
					function chronoforms_validation_signs(formObj){
						formObj.find(":input[class*=validate]").each(function(){
							if($(this).attr("class").indexOf("required") >= 0 || $(this).attr("class").indexOf("group") >= 0){
								var required_parent = [];
								if($(this).closest(".gcore-subinput-container").length > 0){
									var required_parent = $(this).closest(".gcore-subinput-container");
								}else if($(this).closest(".gcore-form-row, .form-group").length > 0){
									var required_parent = $(this).closest(".gcore-form-row, .form-group");
								}
								if(required_parent.length > 0){
									var required_label = required_parent.find("label");
									if(required_label.length > 0 && !required_label.first().hasClass("required_label")){
										required_label.first().addClass("required_label");
										required_label.first().html(required_label.first().html() + " ' . $required_icon . '");
									}
								}
							}
						});
					}
					chronoforms_validation_signs($("#chronoform-' . $form->form['Form']['title'] . '"));
				';
            }
        }
        if (strpos($form_content, 'data-tooltip') !== false) {
            $doc->_('jquery');
            $doc->_('gtooltip');
            if (strpos($form->params->get('theme', 'bootstrap3'), 'bootstrap3') !== false) {
                $tip_icon = '<i class=\'fa fa-exclamation-circle input-tooltip\' style=\'color:#2693FF; padding-left:5px;\'></i>';
            } else {
                $tip_icon = '<span style=\'color:#ff0000; font-size:12px; vertical-align:top;\'>!</span>';
            }
            $js_scripts[] = '
				function chronoforms_data_tooltip(formObj){
					formObj.find(":input").each(function(){
						if($(this).data("tooltip") && $(this).closest(".gcore-input, .gcore-input-wide").length > 0){
							var tipped_parent = [];
							if($(this).closest(".gcore-subinput-container").length > 0){
								var tipped_parent = $(this).closest(".gcore-subinput-container");
							}else if($(this).closest(".gcore-form-row, .form-group").length > 0){
								var tipped_parent = $(this).closest(".gcore-form-row, .form-group");
							}
							if(tipped_parent.length > 0){
								var tipped_label = tipped_parent.find("label");
								if(tipped_label.length > 0 && !tipped_label.first().hasClass("tipped_label")){
									tipped_label.first().addClass("tipped_label");
									var $tip = $("' . $tip_icon . '");
									$tip.data("content", $(this).data("tooltip"));
									tipped_label.first().append($tip);
								}
							}
						}
					});
					formObj.find(".input-tooltip").gtooltip();
				}
				chronoforms_data_tooltip($("#chronoform-' . $form->form['Form']['title'] . '"));
			';
        }
        if (strpos($form_content, 'data-load-state') !== false) {
            $doc->_('jquery');
            $js_scripts[] = '
				function chronoforms_data_loadstate(formObj){
					formObj.find(\':input[data-load-state="disabled"]\').prop("disabled", true);
					formObj.find(\'*[data-load-state="hidden"]\').css("display", "none");
					formObj.find(\':input[data-load-state="hidden_parent"]\').each(function(){
						if($(this).closest(".gcore-subinput-container").length > 0){
							$(this).closest(".gcore-subinput-container").css("display", "none");
						}else if($(this).closest(".gcore-form-row").length > 0){
							$(this).closest(".gcore-form-row").css("display", "none");
						}
					});
				}
				chronoforms_data_loadstate($("#chronoform-' . $form->form['Form']['title'] . '"));
			';
        }
        if (strpos($output, 'data-inputmask=') !== false) {
            $doc->_('jquery');
            $doc->_('jquery.inputmask');
            $js_scripts[] = '$(":input").inputmask();';
        }
        if (strpos($output, 'data-gdatetimepicker') !== false or strpos($output, 'data-fieldtype="gdatetimepicker"') !== false) {
            $doc->_('jquery');
            $doc->_('gdatetimepicker');
            $js_scripts[] = '
			$(\'*[data-gdatetimepicker-format]\').each(function(){
				$(this).data("format", $(this).data("gdatetimepicker-format"));
			});
			';
            //for old data attributes
            $js_scripts[] = '$(\'*[data-gdatetimepicker="1"]\').gdatetimepicker();';
            //for old data attributes
            $js_scripts[] = '$(\'*[data-fieldtype="gdatetimepicker"]\').gdatetimepicker();';
            $js_scripts[] = '
			$(":input").on("select_date.gdatetimepicker", function(){
				if($(this).data("on_date_selected")){
					var on_date_selected = $(this).data("on_date_selected");
					if(on_date_selected in window){
						window[on_date_selected]($(this));
					}
				}
			});
			';
        }
        if (strpos($output, 'multiplier-container') !== false) {
            $doc->_('jquery');
            $js_scripts[] = '
				$(".multiplier-container").each(function(){
					if(typeof($(this).data("hide_first")) != "undefined"){
						$(this).find(".multiplier-contents").first().hide();
					}
					if(typeof($(this).data("disable_first")) != "undefined"){
						$(this).find(".multiplier-contents").first().find(":input").prop("disabled", true);
					}
					if($(this).find(".multiplier-contents").length > 1){
						var counter = $(this).find(".multiplier-contents").length;
						$(this).data("count", counter);
					}
				});
				$(".multiplier-container").find(".multiplier-add-button").on("click", function(){
					var multiplier_container = $(this).closest(".multiplier-container");
					
					var multiplier_clone = multiplier_container.find(".multiplier-contents").first().clone();
					multiplier_clone.find(".multiplier-remove-button").first().css("display", "");
					multiplier_clone.show();
					multiplier_clone.find(":input").prop("disabled", false);
					
					if(typeof(multiplier_container.data("replacer")) != "undefined"){
						var counter = parseInt(multiplier_container.data("count"));
						var multiplier_clone = multiplier_clone.wrap("<p>").parent().html().replace(new RegExp(multiplier_container.data("replacer"), "g"), counter);
						multiplier_container.data("count", counter + 1);
					}
					multiplier_container.find(".multiplier-contents").last().after(multiplier_clone);
				});
				$(document).on("click", ".multiplier-remove-button", function(){
					$(this).closest(".multiplier-contents").remove();
				});
			';
        }
        if ((bool) $config->get('ajax_submit', 0) === true) {
            $doc->_('jquery');
            $doc->_('gtooltip');
            $doc->_('gvalidation', array('lang' => $form->params->get('js_validation_language', 'en')));
            $ajax_url = \GCore\Libs\Url::buildQuery($form_action, array('tvout' => 'ajax'));
            $js_scripts[] = '
					function chrono_ajax_submit(){
						$(document).on("click", "#' . $form_id . ' :input[type=submit]", function(event){
							$("#' . $form_id . '").append("<input type=\'hidden\' name=\'"+$(this).attr("name")+"\' value=\'"+$(this).val()+"\' />");
						});
						
						var files;
						$("input[type=file]").on("change", function(event){
							files = event.target.files;
						});
						
						$(document).on("submit", "#' . $form_id . '", function(event){
							var overlay = $("<div/>").css({
								"position": "fixed",
								"top": "0",
								"left": "0",
								"width": "100%",
								"height": "100%",
								"background-color": "#000",
								"filter": "alpha(opacity=50)",
								"-moz-opacity": "0.5",
								"-khtml-opacity": "0.5",
								"opacity": "0.5",
								"z-index": "10000",
								"background-image":"url(\\"' . \GCore\Helpers\Assets::image('loading-small.gif') . '\\")",
								"background-position":"center center",
								"background-repeat":"no-repeat",
							});
							if(!$("#' . $form_id . '").hasClass("form-overlayed")){
								$("#' . $form_id . '").append(overlay);
								$("#' . $form_id . '").addClass("form-overlayed");
							}
							var form_action = $("#' . $form_id . '").prop("action");
							var sep = (form_action.indexOf("?") > -1) ? "&" : "?";
							var ajax_url = form_action + sep + "tvout=ajax";
							
							//data processing
							$.ajax({
								"type" : "POST",
								"url" : ajax_url,
								"data" : $("#' . $form_id . '").serialize(),
								"success" : function(res){
									$("#' . $form_id . '").replaceWith(res);
									$("#' . $form_id . '").gvalidate();
									chronoforms_fields_events();
									chronoforms_validation_signs($("#' . $form_id . '"));
									chronoforms_data_tooltip($("#' . $form_id . '"));
									chronoforms_data_loadstate($("#' . $form_id . '"));
									if(typeof chronoforms_pageload_fields_events == "function"){
										chronoforms_pageload_fields_events();
									}
									//chrono_ajax_submit();//this line duplicates submissions, should be removed
								},
							});
							return false;
						});
					}
					chrono_ajax_submit();
				';
        }
        $js_scripts[] = implode("\n", $events_codes);
        if (!empty($js_scripts)) {
            $doc->addJsCode('jQuery(document).ready(function($){
				' . implode("\n", $js_scripts) . '
			});');
        }
        if ((bool) $config->get('add_form_tags', 1) === true) {
            echo $form_tag;
        }
        //if ajax then display system messages inside the form
        if ((bool) $config->get('ajax_submit', 0) === true) {
            $doc = \GCore\Libs\Document::getInstance();
            $doc->addCssFile('system_messages');
            $session = \GCore\Libs\Base::getSession();
            $types = $session->getFlash();
            echo \GCore\Helpers\Message::render($types);
        }
        //add fields values
        $output = \GCore\Helpers\DataLoader::load($output, $form->data);
        $output = \GCore\Libs\Str::replacer($output, $form->data, array('repeater' => 'repeater'));
        //show output
        echo $output;
        if ((bool) $config->get('add_form_tags', 1) === true) {
            echo '</form>';
        }
    }
예제 #27
0
파일: apc.php 프로젝트: ejailesb/repo_empr
 function __construct($domain = 'gcore', $params = array('expiration' => 0))
 {
     $this->expiration = !empty($params['expiration']) ? $params['expiration'] : \GCore\Libs\Base::getConfig('app_cache_expiry', 900);
     $this->domain = $this->__safe_id($domain);
 }
예제 #28
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     ob_start();
     eval('?>' . $config->get('template', ''));
     $body = ob_get_clean();
     $others = array();
     //get recipient
     $tos = array();
     if (strlen(trim($config->get('to', '')))) {
         $tos = explode(',', \GCore\Libs\Str::replacer(trim($config->get('to', '')), $form->data));
     }
     if (strlen(trim($config->get('dto', '')))) {
         $dtos = explode(',', trim($config->get('dto', '')));
         foreach ($dtos as $dto) {
             $d_email = explode(',', $form->data($dto));
             $tos = array_merge((array) $d_email, $tos);
         }
     }
     $ccs = array();
     if (strlen(trim($config->get('cc', '')))) {
         $ccs = explode(',', \GCore\Libs\Str::replacer(trim($config->get('cc', '')), $form->data));
     }
     if (strlen(trim($config->get('dcc', '')))) {
         $dccs = explode(',', trim($config->get('dcc', '')));
         foreach ($dccs as $dcc) {
             $d_email = explode(',', $form->data($dcc));
             $ccs = array_merge((array) $d_email, $ccs);
         }
     }
     $others['cc'] = $ccs;
     $bccs = array();
     if (strlen(trim($config->get('bcc', '')))) {
         $bccs = explode(',', \GCore\Libs\Str::replacer(trim($config->get('bcc', '')), $form->data));
     }
     if (strlen(trim($config->get('dbcc', '')))) {
         $dbccs = explode(',', trim($config->get('dbcc', '')));
         foreach ($dbccs as $dbcc) {
             $d_email = explode(',', $form->data($dbcc));
             $bccs = array_merge((array) $d_email, $bccs);
         }
     }
     $others['bcc'] = $bccs;
     //subject
     $subject = trim($config->get('subject', '')) ? \GCore\Libs\Str::replacer($config->get('subject', ''), $form->data) : $form->data($config->get('dsubject', ''));
     //from
     $others['from_name'] = trim($config->get('from_name', '')) ? \GCore\Libs\Str::replacer($config->get('from_name', ''), $form->data) : $form->data($config->get('dfrom_name'), null);
     $others['from_email'] = trim($config->get('from_email', '')) ? \GCore\Libs\Str::replacer($config->get('from_email', ''), $form->data) : $form->data($config->get('dfrom_email'), null);
     //reply to
     $others['reply_name'] = trim($config->get('reply_name', '')) ? \GCore\Libs\Str::replacer($config->get('reply_name', ''), $form->data) : $form->data($config->get('dreply_name'), null);
     $others['reply_email'] = trim($config->get('reply_email', '')) ? \GCore\Libs\Str::replacer($config->get('reply_email', ''), $form->data) : $form->data($config->get('dreply_email'), null);
     $others['type'] = $config->get('email_type', 'html');
     $form->data['ip_address'] = $_SERVER['REMOTE_ADDR'];
     if ($others['type'] == 'html') {
         if ($config->get('append_ip_address', 1)) {
             $body = $body . "<br /><br />" . "IP: {ip_address}";
         }
         $body = \GCore\Libs\Str::replacer($body, $form->data, array('replace_null' => true, 'nl2br' => true, 'repeater' => 'repeater'));
     } else {
         if ($config->get('append_ip_address', 1)) {
             $body = $body . "\n\n" . "IP: {ip_address}";
         }
         $body = \GCore\Libs\Str::replacer($body, $form->data, array('replace_null' => true, 'repeater' => 'repeater'));
     }
     //attach
     $attachments = array();
     if (strlen(trim($config->get('attach', '')))) {
         ob_start();
         $attach_fields = eval('?>' . trim($config->get('attach', '')));
         ob_end_clean();
         if (is_array($attach_fields)) {
             $attachs = array_keys($attach_fields);
             foreach ($form->files as $name => $file) {
                 if (in_array($name, $attachs)) {
                     if (\GCore\Libs\Arr::is_assoc($file)) {
                         $attachments[] = array_merge($attach_fields[$name], array('path' => $file['path']));
                     } else {
                         foreach ($file as $fi => $fv) {
                             //$attachments[] = $fv['path'];
                             $attachments[] = array_merge($attach_fields[$name], array('path' => $fv['path']));
                         }
                     }
                 }
             }
         } else {
             $attachs = explode(',', trim($config->get('attach', '')));
             foreach ($form->files as $name => $file) {
                 if (in_array($name, $attachs)) {
                     if (\GCore\Libs\Arr::is_assoc($file)) {
                         $attachments[] = $file['path'];
                     } else {
                         foreach ($file as $fi => $fv) {
                             $attachments[] = $fv['path'];
                         }
                     }
                 }
             }
         }
     }
     //load global settings
     $settings = $form::_settings();
     if (!empty($settings['mail'])) {
         if (!empty($settings['mail']['smtp']) and empty($settings['mail']['mail_method'])) {
             $settings['mail']['mail_method'] = 'smtp';
         }
         foreach ($settings['mail'] as $k => $v) {
             \GCore\Libs\Base::setConfig($k, $v);
         }
     }
     //encrypt the email
     if ($config->get('encrypt_enabled', 0) == 1 and class_exists('Crypt_GPG')) {
         $mySecretKeyId = trim($config->get('gpg_sec_key', ''));
         //Add Encryption key here
         $gpg = new Crypt_GPG();
         $gpg->addEncryptKey($mySecretKeyId);
         $body = $gpg->encrypt($body);
     }
     $sent = \GCore\Libs\Mailer::send($tos, $subject, $body, $attachments, $others);
     if ($sent) {
         $form->debug[$action_id][self::$title][] = "An email with the details below was sent successfully:";
     } else {
         $form->debug[$action_id][self::$title][] = "An email with the details below could NOT be sent:";
     }
     $form->debug[$action_id][self::$title][] = "To:" . implode(", ", $tos);
     $form->debug[$action_id][self::$title][] = "Subject:" . $subject;
     $form->debug[$action_id][self::$title][] = "From name:" . $others['from_name'];
     $form->debug[$action_id][self::$title][] = "From email:" . $others['from_email'];
     $form->debug[$action_id][self::$title][] = "CC:" . implode(", ", $ccs);
     $form->debug[$action_id][self::$title][] = "BCC:" . implode(", ", $bccs);
     $form->debug[$action_id][self::$title][] = "Reply name:" . $others['reply_name'];
     $form->debug[$action_id][self::$title][] = "Reply email:" . $others['reply_email'];
     $form->debug[$action_id][self::$title][] = "Attachments:";
     $form->debug[$action_id][self::$title][] = $attachments;
     $form->debug[$action_id][self::$title][] = "Body:\n" . $body;
 }
예제 #29
0
 function dispatch($content_only = false)
 {
     Event::trigger('on_before_dispatch', $this);
     $session = Base::getSession();
     reset:
     //if no action set, set it to index
     if (strlen(trim($this->action)) == 0) {
         $this->action = 'index';
     }
     //set admin path
     $site = '';
     if ($this->site == 'admin') {
         $site = '\\Admin';
     }
     //load the extension class
     $controller = !empty($this->controller) ? '\\Controllers\\' . Str::camilize($this->controller) : '\\' . Str::camilize($this->extension);
     $extension = !empty($this->extension) ? '\\Extensions\\' . Str::camilize($this->extension) : '';
     $classname = '\\GCore' . $site . $extension . $controller;
     $this->tvout = strlen(Request::data('tvout', null)) > 0 ? Request::data('tvout') : $this->tvout;
     //set referer
     if (!$content_only) {
         if (!($this->controller == 'users' and ($this->action == 'login' or $this->action == 'logout' or $this->action == 'register')) and (!empty($this->extension) or !empty($this->controller)) and $this->tvout == 'index') {
             //$session->set('_referer', Url::current());
         } else {
             //$session->set('_referer', 'index.php');
         }
     }
     $G_User = $session->get('user', array());
     //check permissions
     $J_User = \JFactory::getUser();
     if (empty($J_User->groups) or empty($G_User['groups']) or array_values($J_User->groups) !== $G_User['groups'] or empty($G_User['inheritance'])) {
         $user_session = array();
         $user_session['id'] = $J_User->id;
         $user_session['name'] = $J_User->name;
         $user_session['username'] = $J_User->username;
         $user_session['email'] = $J_User->email;
         $user_session['last_login'] = $J_User->lastvisitDate;
         $user_session['logged_in'] = !$J_User->guest;
         $user_session['guest'] = $J_User->guest;
         $user_session['groups'] = empty($J_User->groups) ? array(1) : array_values($J_User->groups);
         $user_session['inheritance'] = array();
         if (!empty($J_User->groups)) {
             //sort groups
             $groups = \GCore\Admin\Models\Group::getInstance()->find('all', array('order' => 'Group.parent_id ASC'));
             $valid_groups = array_intersect($user_session['groups'], \GCore\Libs\Arr::getVal($groups, array('[n]', 'Group', 'id')));
             if (!empty($groups) and $valid_groups) {
                 reloop:
                 foreach ($groups as $group) {
                     //if this group exists in the user's groups or its inheitance then add its parent_id
                     if (in_array($group['Group']['id'], $user_session['groups']) or in_array($group['Group']['id'], $user_session['inheritance'])) {
                         $user_session['inheritance'][] = $group['Group']['parent_id'];
                     }
                 }
                 //find the number of occurances of each group in the inheritane
                 $groups_counted = array_count_values($user_session['inheritance']);
                 //if the count of root parent (0 parent_id) is less than the count of user's groups then not all pathes have been found, reloop
                 if (count($user_session['groups']) and !isset($groups_counted[0]) or $groups_counted[0] < count($user_session['groups'])) {
                     goto reloop;
                 } else {
                     $user_session['inheritance'] = array_unique($user_session['inheritance']);
                 }
             }
         }
         if ($session->get('user', array()) !== $user_session) {
             $session->clear('acos_permissions');
         }
         $session->set('user', array_merge($session->get('user', array()), $user_session));
     }
     //copy some config
     $mainframe = \JFactory::getApplication();
     //set timezone
     date_default_timezone_set($mainframe->getCfg('offset'));
     //site title
     \GCore\Libs\Base::setConfig('site_title', $mainframe->getCfg('sitename'));
     //$lang = \JFactory::getLanguage();
     //\GCore\Libs\Base::setConfig('site_language', $lang->getTag());
     /*if(!Authorize::authorized($classname, $this->action)){
     			if($content_only){
     				return;
     			}
     			$this->redirect(r_('index.php?cont=users&act=login'));
     		}*/
     //if the extension class not found or the action function not found then load an error
     if (!class_exists($classname) or !in_array($this->action, get_class_methods($classname)) and !in_array('__call', get_class_methods($classname)) or substr($this->action, 0, 1) == '_') {
         $this->controller = 'errors';
         $this->action = 'e404';
         //reset the controller
         //$classname = '\GCore\Controllers\Errors';
         $this->buffer = 'Page not found';
         \GCore\Libs\Env::e404();
         \JError::raiseError(404, $this->buffer);
         //we need the rendered content only
         if ($content_only) {
             return;
         }
     }
     //load language file
     if (!empty($extension)) {
         Lang::load($site . $extension);
     }
     //set theme
     $doc = Document::getInstance($this->site, $this->thread);
     $doc->theme = 'bootstrap3';
     $theme = \GCore\Helpers\Theme::getInstance();
     //load class and run the action
     ${$classname} = new $classname($this->site, $this->thread);
     ob_start();
     $continue = ${$classname}->_initialize();
     //check and read cache
     if (!empty(${$classname}->cache)) {
         if (!is_array(${$classname}->cache)) {
             ${$classname}->cache = array();
         }
         if (empty(${$classname}->cache['time'])) {
             ${$classname}->cache['time'] = Base::getConfig('app_cache_expiry', 900);
         }
         if (empty(${$classname}->cache['title'])) {
             ${$classname}->cache['title'] = File::makeSafe($classname . '_' . $this->action);
         } else {
             ${$classname}->cache['title'] = File::makeSafe(${$classname}->cache['title']);
         }
         if (empty(${$classname}->cache['key'])) {
             ${$classname}->cache['key'] = 'cached_view';
         } else {
             ${$classname}->cache['key'] = 'cached_view_' . ${$classname}->cache['key'];
         }
         $cache = Cache::getInstance(${$classname}->cache['title'], array('expiration' => ${$classname}->cache['time']));
         $cached_view = $cache->get(${$classname}->cache['key']);
         $cached = false;
         if (!empty($cached_view)) {
             $cached = true;
             $continue = false;
             echo $cached_view;
         }
     }
     if ($continue !== false) {
         ${$classname}->{$this->action}();
         if ($this->reset === true) {
             $this->reset = false;
             goto reset;
         }
         //initialize and render view
         $view = new View();
         $view->initialize(${$classname});
         $view->renderView($this->action);
     }
     //get the action output buffer
     $this->buffer = ob_get_clean();
     //check and save cache
     if (!empty(${$classname}->cache) and !$cached) {
         $cache = Cache::getInstance(${$classname}->cache['title'], array('expiration' => ${$classname}->cache['time']));
         $cache->set(${$classname}->cache['key'], $this->buffer);
     }
     //finalize
     ob_start();
     ${$classname}->_finalize();
     $this->buffer .= ob_get_clean();
     if ($this->tvout != 'ajax' and $doc->theme == 'bootstrap3') {
         $this->buffer = '<div class="gbs3">' . $this->buffer . '</div>';
     }
     //Event::trigger('on_after_dispatch');
 }
예제 #30
0
파일: form.php 프로젝트: ejailesb/repo_empr
 function translate($data = '')
 {
     $_f = function ($e) {
         $cs = explode('=', $e, 2);
         return array_map('trim', $cs);
     };
     $site_lang = \GCore\Libs\Str::camilize(str_replace('-', '_', strtolower(\GCore\Libs\Base::getConfig('site_language'))));
     if (!empty($this->form['Form']['extras']['locales'])) {
         foreach ($this->form['Form']['extras']['locales'] as $l => $lang_data) {
             $tag = $lang_data['lang_tag'];
             $tag_cap = \GCore\Libs\Str::camilize($tag);
             if ($tag_cap == $site_lang) {
                 $lines = explode("\n", $lang_data['strings']);
                 $strings = array_map($_f, $lines);
                 $texts = \GCore\Libs\Arr::getVal($strings, array('[n]', 0));
                 if (!empty($lang_data['strict'])) {
                     $texts = array_map(function ($text) {
                         return '[' . $text . ']';
                     }, $texts);
                 }
                 $locales = \GCore\Libs\Arr::getVal($strings, array('[n]', 1));
                 $data = str_replace($texts, $locales, $data);
             }
         }
     }
     return $data;
 }