Esempio n. 1
0
 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;
     }
 }
Esempio n. 2
0
 function afterFind($type, &$data)
 {
     parent::afterFind($type, $data);
     if (!empty($data) and is_array($data)) {
         foreach ($data as $k => $record) {
             if (isset($data[$k][$this->alias]['settings'])) {
                 $data[$k][$this->alias]['settings'] = json_decode($data[$k][$this->alias]['settings'], true);
             }
         }
     }
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 function afterSave()
 {
     parent::afterSave();
     $this->save_tree_node($this->data);
 }
Esempio n. 5
0
	function beforeSave(&$data, &$params, $mode){
		foreach($data['extras']['actions_config'] as $f_k => $f_info){
			if(strpos($f_k, '{N}') !== false){
				unset($data['extras']['actions_config'][$f_k]);
			}
		}
		if(!empty($data['extras']['fields']) AND $data['form_type'] == '1'){
			foreach($data['extras']['fields'] as $f_k => $f_info){
				if(strpos($f_k, '{N}') !== false){
					unset($data['extras']['fields'][$f_k]);
				}
			}
			//$data['wizardcode'] = serialize($data['fields_config']);
			if(!empty($data['extras']['fields'])){
				ob_start();
				\GCore\Helpers\Html::active_set('div');//!empty($data['params']['html_helper_set']) ? $data['params']['html_helper_set'] : 'div');
				/*if(!empty($data['params']['theme']) AND $data['params']['theme'] != 'bootstrap3'){
					$doc = \GCore\Libs\Document::getInstance();
					$doc->theme = $data['params']['theme'];
				}*/
				$theme = !empty($data['params']['theme']) ? $data['params']['theme'] : '';
				$doc = \GCore\Libs\Document::getInstance();
				$doc->theme = $theme;
				//echo \GCore\Helpers\Html::formSecStart();

				$containers_ids = array();
				$containers_configs = array();
				foreach($data['extras']['fields'] as $k => $field){
					if($field['type'] == 'multi' AND isset($field['inputs'])){
						foreach($field['inputs'] as $sub_id => $input){
							$field['inputs'][$sub_id] = $this->fix_field_data($field['inputs'][$sub_id]);
						}
					}else{
						$field = $this->fix_field_data($field);
					}
					if($field['type'] == 'container'){
						//if this container is also a root container then close existing ones
						if($field['container_id'] == 0){
							//close all open containers
							foreach($containers_ids as $containers_id){
								$container_id = array_pop($containers_ids);
								echo $this->build_container_code($containers_configs[$container_id], 'end', $k);
							}
						}else{
							check_parent_container:
							if(!empty($containers_ids)){
								$last_container_id = array_pop($containers_ids);
								if($field['container_id'] == $last_container_id){
									//do nothing, we should add the field as regular
									array_push($containers_ids, $last_container_id);
								}else{
									//one container has just ended, because the element belongs to a differnt one, close it
									echo $this->build_container_code($containers_configs[$last_container_id], 'end', $k);
									goto check_parent_container;
								}
							}
						}
						echo $this->build_container_code($field, 'start', $k);
						array_push($containers_ids, $k);
						$containers_configs[$k] = $field;
					}else{
						if(isset($field['container_id'])){
							if($field['container_id'] == 0){
								//close all open containers
								foreach(array_keys($containers_ids) as $c_k){
									$container_id = array_pop($containers_ids);
									echo $this->build_container_code($containers_configs[$container_id], 'end', $k);
								}
							}else{
								check_container:
								if(!empty($containers_ids)){
									$last_container_id = array_pop($containers_ids);
									if($field['container_id'] == $last_container_id){
										//do nothing, we should add the field as regular
										array_push($containers_ids, $last_container_id);
									}else{
										//one container has just ended, because the element belongs to a differnt one, close it
										echo $this->build_container_code($containers_configs[$last_container_id], 'end', $k);
										goto check_container;
									}
								}
							}
						}

						if($field['type'] == 'hidden' OR !empty($field['pure_code'])){
							echo \GCore\Helpers\Html::input($field['name'], $field);
						}else{
							if(!empty($field['dynamic_data']['enabled']) AND !empty($field['dynamic_data']['data_path']) AND !empty($field['dynamic_data']['value_key']) AND !empty($field['dynamic_data']['text_key'])){
								echo $this->build_dynamic_element($field);
							}else{
								/*if(isset($field['label'])){
									$position = isset($field['label_pos']) ? $field['label_pos'] : 'left';
									$field['label'] = array('text' => $field['label'], 'position' => $position);
								}*/
								if($field['type'] == 'multi' AND isset($field['inputs'])){
									foreach($field['inputs'] as $sub_id => $input){
										if(!empty($input['dynamic_data']['enabled']) AND !empty($input['dynamic_data']['data_path']) AND !empty($input['dynamic_data']['value_key']) AND !empty($input['dynamic_data']['text_key'])){
											$field['inputs'][$sub_id]['code'] = $this->build_dynamic_element($input, true);
											$field['inputs'][$sub_id]['type'] = 'custom';
											//$field['inputs'][$sub_id]['label'] = '';
										}
									}
									echo \GCore\Helpers\Html::formLine($field['name'], $field);
								}else{
									echo \GCore\Helpers\Html::formLine($field['name'], $field);
								}
								//echo \GCore\Helpers\Html::formLine($field['name'], $field);
							}
						}
					}
				}
				//close any empty containers with no fields after them
				while($container_id = array_pop($containers_ids)){
					echo $this->build_container_code($containers_configs[$container_id], 'end', $container_id);
				}
				//echo \GCore\Helpers\Html::formSecEnd();
				//echo \GCore\Helpers\Html::formEnd();
				$data['content'] = ob_get_clean();
			}else{
				$data['content'] = '';
			}
		}
		foreach($data['extras']['actions_config'] as $k => $act_info){
			if(!empty($act_info['__action_title__'])){
				$action_title = $act_info['__action_title__'];
				$classname = '\GCore\Admin\Extensions\Chronoforms\Actions\\'.\GCore\Libs\Str::camilize($action_title)."\\".\GCore\Libs\Str::camilize($action_title);
				if(method_exists($classname, 'on_form_save')){
					${$classname} = new $classname();
					${$classname}->on_form_save($data, $k);
				}
			}
		}
		if(!empty(self::$tabs)){
			foreach(self::$tabs as $container_id => $tabs){
				$tabs_bar = '';
				foreach($tabs as $tab_id => $tab_title){
					$tab_class = empty($tabs_bar) ? ' class="active"' : '';
					$tabs_bar .= '<li'.$tab_class.'><a href="#'.$tab_id.'" data-g-toggle="tab">'.$tab_title.'</a></li>';
				}
				$data['content'] = str_replace('__TABS_TITLES__'.$container_id.'__', $tabs_bar, $data['content']);
			}
		}
		parent::beforeSave($data, $params, $mode);
	}
Esempio n. 6
0
 function _initialize()
 {
     //$this->area = 'front';
     $session = \GCore\Libs\Base::getSession();
     if ($this->get('ccname', null)) {
         $this->data['ccname'] = $this->get('ccname');
     }
     if (!empty($this->data['ccname'])) {
         $this->connection = $connection = $this->Connection->find('first', array('conditions' => array('title' => $this->data['ccname'], 'published' => 1)));
         if (!empty($connection['Connection']['extras']['models']['name'][1]) and !empty($connection['Connection']['extras']['models']['tablename'][1])) {
             $dbo_config = array();
             if (!empty($connection['Connection']['extras']['ndb']['enabled'])) {
                 $dbo_config = array('type' => $connection['Connection']['extras']['ndb']['driver'], 'host' => $connection['Connection']['extras']['ndb']['host'], 'name' => $connection['Connection']['extras']['ndb']['database'], 'user' => $connection['Connection']['extras']['ndb']['user'], 'pass' => $connection['Connection']['extras']['ndb']['password'], 'prefix' => $connection['Connection']['extras']['ndb']['prefix']);
             }
             //primary model available
             \GCore\Libs\GModel::generateModel(trim($connection['Connection']['extras']['models']['name'][1]), array('tablename' => trim($connection['Connection']['extras']['models']['tablename'][1]), 'dbo_config' => $dbo_config));
             $pmodel = '\\GCore\\Models\\' . $connection['Connection']['extras']['models']['name'][1];
             $this->pmodel = $pmodel::getInstance();
             $this->connection_models[$this->pmodel->alias] = $this->pmodel;
             //find secondary models if available
             foreach ($this->connection['Connection']['extras']['models']['name'] as $k => $name) {
                 if ($k != 1) {
                     $name = trim($this->connection['Connection']['extras']['models']['name'][$k]);
                     $tablename = trim($this->connection['Connection']['extras']['models']['tablename'][$k]);
                     $pkey = !empty($this->connection['Connection']['extras']['models']['pkey'][$k]) ? trim($this->connection['Connection']['extras']['models']['pkey'][$k]) : NULL;
                     if (!empty($name) and !empty($tablename)) {
                         \GCore\Libs\GModel::generateModel($name, array('tablename' => $tablename, 'pkey' => $pkey, 'dbo_config' => $dbo_config));
                         //setup relation to primary if exists
                         $relation = $this->connection['Connection']['extras']['models']['relation'][$k];
                         if (!empty($relation)) {
                             $relation_settings = array('className' => '\\GCore\\Models\\' . $name);
                             if (!empty($this->connection['Connection']['extras']['models']['foreignKey'][$k])) {
                                 $relation_settings['foreignKey'] = trim($this->connection['Connection']['extras']['models']['foreignKey'][$k]);
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['assoc_save'][$k])) {
                                 $relation_settings['save_on_save'] = true;
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['assoc_delete'][$k])) {
                                 $relation_settings['delete_on_delete'] = true;
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['conditions'][$k])) {
                                 $conditions = eval('?>' . $this->connection['Connection']['extras']['models']['conditions'][$k]);
                                 $relation_settings['conditions'] = is_array($conditions) ? $conditions : array();
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['join_conditions'][$k])) {
                                 $join_conditions = eval('?>' . $this->connection['Connection']['extras']['models']['join_conditions'][$k]);
                                 $relation_settings['join_conditions'] = is_array($join_conditions) ? $join_conditions : array();
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['join_type'][$k])) {
                                 $relation_settings['type'] = $this->connection['Connection']['extras']['models']['join_type'][$k];
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['fields'][$k])) {
                                 $relation_settings['fields'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['fields'][$k]);
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['order'][$k])) {
                                 $relation_settings['order'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['order'][$k]);
                             }
                             if (!empty($this->connection['Connection']['extras']['models']['group'][$k])) {
                                 $relation_settings['group'] = $this->_process_fields_list($this->connection['Connection']['extras']['models']['group'][$k]);
                             }
                             if (empty($this->connection['Connection']['extras']['models']['associated_model'][$k])) {
                                 $this->pmodel->bindModels($relation, array($name => $relation_settings));
                                 $this->connection_models[$name] = $this->pmodel->{$name};
                             } else {
                                 $associated_model = $this->connection['Connection']['extras']['models']['associated_model'][$k];
                                 $associated_model_class = '\\GCore\\Models\\' . $this->connection['Connection']['extras']['models']['associated_model'][$k];
                                 if ($associated_model == $this->pmodel->alias) {
                                     $this->pmodel->bindModels($relation, array($name => $relation_settings));
                                     $this->connection_models[$name] = $this->pmodel->{$name};
                                 } else {
                                     $check_model = $this->pmodel;
                                     check_again:
                                     if (in_array($associated_model, array_keys($check_model->associated_models))) {
                                         $check_model->{$associated_model}->bindModels($relation, array($name => $relation_settings));
                                         $this->connection_models[$name] = $check_model->{$associated_model}->{$name};
                                     } else {
                                         $sub_models = array_keys($check_model->associated_models);
                                         foreach ($sub_models as $sub_model) {
                                             $check_model = $sub_model;
                                             goto check_again;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             $session->setFlash('error', l_('CONN_CONNECTION_NOT_FOUND'));
             return false;
         }
     } else {
         $session->setFlash('error', l_('CONN_NO_CONNECTION_NAME'));
         return false;
     }
     //check permissions
     if (!empty($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action])) {
         $gcb = $this->Request->data('gcb', null);
         $owner_id = null;
         if ($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action]['owner'] == 1) {
             if (!empty($gcb) and !empty($this->connection['Connection']['extras'][$this->area]['permissions_conf']['owner_id_column'])) {
                 $user_id_column = $this->connection['Connection']['extras'][$this->area]['permissions_conf']['owner_id_column'];
                 $records = $this->pmodel->find('all', array('recursive' => -1, 'fields' => array($this->pmodel->pkey, $user_id_column), 'conditions' => array($this->pmodel->pkey => $gcb)));
                 if (strpos($user_id_column, '.') === false) {
                     $user_id_column = $this->pmodel->alias . '.' . $user_id_column;
                 }
                 $owners = \GCore\Libs\Arr::getVal($records, explode('.', '[n].' . $user_id_column));
                 $owners = array_values(array_unique($owners));
                 if (count($owners) > 1) {
                     goto check_all;
                 } else {
                     $owner_id = $owners[0];
                 }
             }
         }
         check_all:
         if (!\GCore\Libs\Authorize::check_rules($this->connection['Connection']['extras'][$this->area]['permissions'][$this->action], \GCore\Libs\Authenticate::get_user_groups(), $owner_id)) {
             $session->setFlash('error', l_('CONNECTIVITY_ACCESS_DENIED'));
             return false;
         }
     }
     //load plugins
     if (!empty($this->pmodel)) {
         if (!empty($this->connection['Connection']['extras'][$this->area]['display']['page_limit']) and is_numeric($this->connection['Connection']['extras'][$this->area]['display']['page_limit'])) {
             $this->pmodel->page_limit = (int) $this->connection['Connection']['extras'][$this->area]['display']['page_limit'];
         }
         //run plugins
         if (!empty($this->connection['Connection']['extras']['plugins'])) {
             //sort plugins execution
             $plugins_priority = array();
             foreach ($this->connection['Connection']['extras']['plugins'] as $plg => $plg_data) {
                 $plugins_priority[$plg] = \GCore\Libs\Arr::getVal($plg_data, array('priority'), 0);
             }
             array_multisort($plugins_priority, SORT_DESC, $this->connection['Connection']['extras']['plugins']);
             foreach ($this->connection['Connection']['extras']['plugins'] as $plugin => $plugin_data) {
                 if (!empty($plugin_data['enabled'])) {
                     $this->plugins[] = $plugin;
                     if (class_exists('\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Plugins\\' . \GCore\Libs\Str::camilize($plugin) . '\\' . \GCore\Libs\Str::camilize($plugin . '_helper'))) {
                         $plugin_helper = '\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Plugins\\' . \GCore\Libs\Str::camilize($plugin) . '\\' . \GCore\Libs\Str::camilize($plugin . '_helper');
                         $this->helpers[$plugin_helper]['connection'] = $this->connection;
                         $this->helpers[$plugin_helper]['model'] = $this->pmodel;
                     }
                 }
             }
         }
         $this->helpers['\\GCore\\Admin\\Extensions\\Chronoconnectivity\\Helpers\\Plugin']['plugins'] = $this->plugins;
         $this->_process_plugins('on_initialize', $this);
     }
 }
Esempio n. 7
0
 function execute(&$form, $action_id)
 {
     $config = $form->actions_config[$action_id];
     $config = new \GCore\Libs\Parameter($config);
     $this->config = $config;
     //set activation link
     if (trim($this->config->get('activation_link', '')) == '') {
         $this->config->set('activation_link', 'index.php?option=com_users&task=registration.activate');
     }
     // Get required system objects
     $user = clone JFactory::getUser();
     $mainframe = JFactory::getApplication();
     //$config		= JFactory::getConfig();
     $authorize = JFactory::getACL();
     $document = JFactory::getDocument();
     $language = JFactory::getLanguage();
     $language->load('com_users');
     // If user registration is not allowed, show 403 not authorized.
     $usersConfig = JComponentHelper::getParams('com_users');
     if ($usersConfig->get('allowUserRegistration') == '0' && !$config->get('override_allow_user_registration', 0)) {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     // Initialize new usertype setting
     $userConfig = JComponentHelper::getParams('com_users');
     // Default to Registered.
     $defaultUserGroup = $config->get('new_usertype', '');
     if (empty($defaultUserGroup)) {
         $defaultUserGroup = $userConfig->get('new_usertype', array(2));
     } else {
         $_groups = $defaultUserGroup;
         //explode(",", trim($defaultUserGroup));
         $defaultUserGroup = array();
         foreach ($_groups as $_group) {
             $defaultUserGroup[] = (int) $_group;
         }
     }
     //set the post fields values
     $form->data['name'] = $form->data($config->get('name', ''), '');
     $form->data['username'] = $form->data($config->get('username', ''), '');
     $form->data['email'] = $form->data($config->get('email', ''), '');
     $form->data['password'] = $form->data($config->get('password', ''), '');
     $form->data['password2'] = $form->data($config->get('password2', ''), '');
     //generate the random pass if enabled
     if ((int) $config->get('random_password', 0) == 1) {
         jimport('joomla.user.helper');
         $random_pass = JUserHelper::genRandomPassword();
         $form->data['password'] = $random_pass;
         $form->data['password2'] = $random_pass;
     }
     //check empty fields
     $checks = array('name', 'username', 'email', 'password');
     foreach ($checks as $check) {
         if (!trim($form->data[$check])) {
             $this->events['fail'] = 1;
             $form->errors[$config->get($check)] = 'You must provide your ' . $check . '.';
             //return false;
         }
     }
     if ($this->events['fail'] == 1) {
         return false;
     }
     //check the 2 passwords
     if ($form->data['password'] != $form->data['password2']) {
         $this->events['fail'] = 1;
         $form->errors[$config->get('password2')] = 'Passwords do NOT match.';
         $form->debug[] = "Couldn't create new user, Passwords do NOT match.";
         return false;
     }
     // Bind the post array to the user object
     $post_data = $form->data;
     if (!$user->bind($post_data, 'usertype')) {
         //JError::raiseError( 500, $user->getError());
         $this->events['fail'] = 1;
         $form->errors[] = $user->getError();
         $form->debug[] = "Couldn't bind new user, Joomla returned this error : " . $user->getError();
         return false;
     }
     // Set some initial user values
     $user->set('id', 0);
     $user->set('usertype', 'deprecated');
     $user->set('groups', $defaultUserGroup);
     $date = JFactory::getDate();
     $user->set('registerDate', date('Y-m-d H:i:s', time()));
     // If user activation is turned on, we need to set the activation information
     $useractivation = $config->get('useractivation', $usersConfig->get('useractivation'));
     if ($useractivation == 1 || $useractivation == 2) {
         jimport('joomla.user.helper');
         $user->set('activation', md5(JUserHelper::genRandomPassword()));
         $user->set('block', '1');
     }
     // If there was an error with registration, set the message and display form
     if (!$user->save()) {
         /*JError::raiseWarning('', JText::_( $user->getError()));
         		$this->register();*/
         $this->events['fail'] = 1;
         $form->errors[] = $user->getError();
         $form->debug[] = "Couldn't save new user, Joomla returned this error : " . $user->getError();
         return false;
     } else {
         $this->events['success'] = 1;
     }
     //store user data
     $user_data = (array) $user;
     $removes = array('params', '_params', 'guest', '_errorMsg', '_errors');
     foreach ($removes as $remove) {
         unset($user_data[$remove]);
     }
     $form->data['_PLUGINS_']['joomla_registration'] = $user_data;
     //inject user data under the correct data path
     if (strlen(trim($config->get('user_data_path', ''))) > 0) {
         $form->data = $form->set_array_value($form->data, explode('.', trim($config->get('user_data_path', ''))), $user_data);
     }
     //CB support
     if ((bool) $config->get('enable_cb_support', 0) === true) {
         /********************CB part*************************/
         $database = JFactory::getDBO();
         $database->setQuery("SELECT * FROM #__comprofiler_fields WHERE `table`='#__comprofiler' AND name <>'NA' AND registration = '1'");
         $fields = $database->loadObjectList();
         $default_fields_names = array('id', 'user_id');
         $default_fields_values = array('id' => $user_data['id'], 'user_id' => $user_data['id']);
         foreach ($fields as $field) {
             $default_fields_names[] = $field->name;
             $fieldname = $field->name;
             $default_fields_values[$fieldname] = $form->data($fieldname, '');
         }
         /*$database->setQuery( "INSERT INTO #__comprofiler (".implode(",", $default_fields_names).") VALUES  ('".implode("','", $form->escapeVar($default_fields_values))."');" );
         		if (!$database->query()) {
         			JError::raiseWarning(100, $database->getErrorMsg());
         		}*/
         \GCore\Libs\GModel::generateModel('Profiler', array('tablename' => '#__comprofiler'));
         \GCore\Models\Profiler::getInstance()->save($default_fields_values);
         /**********************************************/
     }
     // Send registration confirmation mail
     $password = $form->data['password'];
     //JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     //Disallow control chars in the email
     if ((int) $config->get('send_joo_activation', 0) == 1) {
         $this->_sendMail($user, $password, $config);
     }
     // Everything went fine, set relevant message depending upon user activation state and display message
     if ((int) $useractivation == 2) {
         $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY');
     } else {
         if ((int) $useractivation == 1) {
             $message = JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE');
         } else {
             $message = JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS');
         }
     }
     if ($config->get('display_reg_complete', 0) == 1) {
         echo $message;
     }
     if ((int) $config->get('auto_login', 0) == 1) {
         $credentials = array();
         $credentials['username'] = $form->data['username'];
         $credentials['password'] = $form->data['password'];
         $mainframe->login($credentials);
     }
 }