Example #1
0
 public function query($table_name)
 {
     //$table_name = $_POST['table_name'];
     $query = $_GET['term'];
     $sys_object = new Crud_Models_Object();
     $sys_object->load($table_name, 'table_name');
     $sys_object->loadFieldsForObject();
     $searchable_fields = array();
     foreach ($sys_object->sys_field_list as $sys_field) {
         if ($sys_field->is_hidden == 0 && $sys_field->is_identification == 1) {
             $searchable_fields[] = $sys_field->field_name;
         }
     }
     $data = array();
     $sql = "SELECT id, " . implode(', ', $searchable_fields) . "\r\n\t\t        FROM {$table_name} \r\n\t\t        WHERE is_deleted = 0 AND (";
     foreach ($searchable_fields as $searchable_field) {
         $sql .= " {$searchable_field} LIKE ?";
         $data[] = "%" . $query . "%";
         if (end($searchable_fields) != $searchable_field) {
             $sql .= " OR";
         } else {
             $sql .= ')';
         }
     }
     $results = Libraries_Db_Factory::getDb()->fetchAll($sql, $data, Libraries_Db_Adapter::FETCH_TYPE_ASSOC);
     $response = array();
     foreach ($results as $result) {
         $id = array_shift($result);
         $response[] = array('id' => $id, 'value' => implode(', ', $result));
     }
     echo json_encode($response);
 }
Example #2
0
 public function content($sys_object_id)
 {
     $sys_object = new Crud_Models_Object();
     $sys_object->load(intval($sys_object_id));
     $sys_object->loadFieldsForObject();
     if ($sys_object->is_system == 1 && $this->user->role->safe_title != 'administrator') {
         echo '<script>window.location="' . SITE_ROOT_URI . '/admin/error/' . '"</script>';
         exit;
     }
     if (!$this->user->role->canExecuteAction('can_view_' . $sys_object->table_name)) {
         echo '<script>window.location="' . SITE_ROOT_URI . '/admin/error/' . '"</script>';
         exit;
     }
     $order = array();
     $order[] = array('title', 'ASC');
     $role = new Libraries_Db_Mysql_Model('adm_user_role');
     $roles = $role->search(array(), $order);
     if (isset($_POST) && !empty($_POST)) {
         foreach ($roles as $role) {
             $sql = "DELETE \r\n\t\t\t\t\t\tFROM adm_user_role_permission\r\n\t\t\t\t\t\tWHERE id_adm_user_role = ?";
             $data = array($role->id);
             Libraries_Db_Factory::getDb()->execute($sql, $data);
             foreach ($_POST as $action => $data) {
                 $permission = new Libraries_Db_Mysql_Model('adm_user_role_permission');
                 $permission->id_adm_user_role = $role->id;
                 $permission->action = $action;
                 $permission->is_active = array_key_exists($role->id, $data) && $data[$role->id] == 1 ? 1 : 0;
                 $permission->save();
             }
         }
         Libraries_Flashdata::set('saved', __('Permissions is saved'));
     }
     $order = array();
     $order[] = array('table_name', 'ASC');
     $where = array();
     $where[] = array('AND', 'is_system', '!=', 1);
     $objects = $sys_object->search($where, $order);
     Libraries_View::getInstance()->roles = $roles;
     Libraries_View::getInstance()->objects = $objects;
     Libraries_View::getInstance()->saved_status = Libraries_Flashdata::get('saved');
     $content = Libraries_View::getInstance()->setModule('admin')->load('permissions');
     Libraries_Layout::getInstance()->setTheme('admin');
     Libraries_Layout::getInstance()->setLayout('admin');
     Libraries_Layout::getInstance()->setRegionContent('content', $content);
     Libraries_Layout::getInstance()->render();
 }
Example #3
0
 public function query()
 {
     $sys_object_id = intval($_POST['sys_object_id']);
     $sys_object = new Crud_Models_Object();
     $sys_object->load($sys_object_id);
     $sys_object->loadFieldsForObject();
     $data = new Libraries_Db_Mysql_Model($sys_object->table_name);
     $data = $data->search();
     $response = array();
     foreach ($data as $row) {
         $text_value = '';
         foreach ($sys_object->sys_field_list as $sys_field) {
             if ($sys_field->is_identification == 1 && array_key_exists($sys_field->field_name, $row->data)) {
                 $text_value .= $row->{$sys_field->field_name} . ', ';
             }
         }
         $item = array($row->id, trim($text_value, ', '));
         $response[] = $item;
     }
     echo json_encode($response);
 }
Example #4
0
<?php

$table_name = $control_properties->table_name;
$sys_object = new Crud_Models_Object();
$sys_object->load($table_name, 'table_name');
$sys_object->loadFieldsForObject();
$data = new Libraries_Db_Mysql_Model($sys_object->table_name);
$data = $data->search();
?>
<div class="ocp-select">
	<select id="<?php 
echo $field->field_name;
?>
" name="<?php 
echo $field->field_name;
?>
" class="form-control" tabindex="<?php 
echo $index;
?>
">
		<option value=""></option>
		
		<?php 
if (!empty($data)) {
    ?>
			<?php 
    foreach ($data as $row) {
        ?>
				<option value="<?php 
        echo $row->id;
        ?>
Example #5
0
 public function getfields()
 {
     $object = new Crud_Models_Object();
     $object->load(intval($_POST['sys_object_id']));
     $object->loadFieldsForObject();
     $response = array();
     foreach ($object->sys_field_list as $field) {
         if ($field->is_hidden == 1) {
             continue;
         }
         $response[] = $field->data;
     }
     echo json_encode($response);
 }
Example #6
0
 public function search($sys_object_id)
 {
     $sys_object = new Crud_Models_Object();
     $sys_object->load(intval($sys_object_id));
     $sys_object->loadFieldsForObject();
     Libraries_View::getInstance()->sys_object = $sys_object;
     echo Libraries_View::getInstance()->setModule('crud')->load('search');
 }