public function getModifyForm() { $field_id = intval($_POST['field_id']); $control_id = intval($_POST['control_id']); $field = new Crud_Models_Field(); $field->load($field_id); $field->loadValidators(); $field->loadControl(); $control = new Controls_Models_Control(); $control->load($control_id); echo call_user_func(array(new $control->class(), 'modifyForm'), $field); }
/** * * @return Objectmanager_Models_Object */ public function loadFieldsForObject() { $where = array(); $order = array(array('order_index', 'DESC')); // get all fields for object $where[] = array('AND', 'id_sys_object', '=', intval($this->id)); $sys_field = new Crud_Models_Field(); $sys_field_list = $sys_field->search($where, $order); foreach ($sys_field_list as $sys_field) { $this->sys_field_list[$sys_field->field_name] = $sys_field; } return $this; }
public function reordermanual() { $object = new Crud_Models_Object(); $object->load($_POST['object_id']); $field = new Crud_Models_Field(); $field->load($_POST['field_id']); $row = new Libraries_Db_Mysql_Model($object->table_name); $row->load($_POST['row_id']); $where = array(); $order = array(); $replacement_row = new Libraries_Db_Mysql_Model($object->table_name); $replacement_row->load(intval($_POST['value']), $field->field_name); if ($replacement_row->isEmpty()) { $sql = "SELECT MIN({$field->field_name}) as min, MAX({$field->field_name}) as max\r\n\t\t\t\t\tFROM {$object->table_name}\r\n\t\t\t\t\tWHERE is_deleted = 0"; $min_max = Libraries_Db_Factory::getDb()->fetchRow($sql, array(), Libraries_Db_Adapter::FETCH_TYPE_CLASS); if ($_POST['value'] < $min_max->min) { $replacement_row = $replacement_row->load($min_max->min, $field->field_name); $_POST['value'] = $min_max->min; } if ($_POST['value'] > $min_max->max) { $replacement_row = $replacement_row->load($min_max->max, $field->field_name); $_POST['value'] = $min_max->max; } /* $response = array(); $response['error'] = 'Can\'t find this object'; echo json_encode($response); return; */ } $replacement_row->{$field->field_name} = $row->{$field->field_name}; $replacement_row->save(); $row->{$field->field_name} = $_POST['value']; $row->save(); $response = array(); $response['success'] = 1; echo json_encode($response); return; }
public function modify($sys_object_id) { $sys_object = new Crud_Models_Object(); $sys_object->load(intval($sys_object_id)); $sys_object->loadFieldsForObject(); if (isset($_POST) && !empty($_POST)) { $field_list = array(); $sys_object->table_title = $_POST['table_title']; $sys_object->group_name = $_POST['group_name']; $sys_object->custom_crud_class = $_POST['custom_crud_class']; $sys_object->is_system = isset($_POST['is_system']) && $_POST['is_system'] == 1 ? 1 : 0; $sys_object->save(); foreach ($_POST['field_title'] as $field_id => $field_title) { $properties = array(); foreach ($_POST as $key => $value) { if (preg_match('/^control-properties-/', $key) && isset($value[$field_id])) { $property_key = str_replace('control-properties-', '', $key); $properties[$property_key] = $value[$field_id]; } } $field = new Crud_Models_Field(); $field->load($field_id); if ($field->isEmpty()) { $field->id_sys_object = $sys_object->id; } $field->id_sys_control = isset($_POST['id_sys_control'][$field_id]) ? intval($_POST['id_sys_control'][$field_id]) : 0; $field->ids_sys_validator = isset($_POST['ids_sys_validator'][$field_id]) ? implode(',', $_POST['ids_sys_validator'][$field_id]) : ''; $field->field_title = $field_title; $field->field_description = $_POST['field_description'][$field_id]; $field->order_index = $_POST['order_index'][$field_id]; $field->is_hidden = isset($_POST['is_hidden'][$field_id]) ? intval($_POST['is_hidden'][$field_id]) : 0; $field->is_identification = isset($_POST['is_identification'][$field_id]) ? intval($_POST['is_identification'][$field_id]) : 0; $field->sys_control_properties = !empty($properties) ? json_encode($properties) : ''; $field->save(); } foreach ($_POST['id_sys_object_child'] as $relation_id => $id_sys_object_child) { $subform = new Crud_Models_Subform(); $subform->load($relation_id); if (!$subform->isEmpty()) { if ($subform->id_sys_object_parent != $sys_object->id) { $subform = new Crud_Models_Subform(); } } if (isset($_POST['delete']) && isset($_POST['delete'][$relation_id]) && $_POST['delete'][$relation_id] == 1) { $subform->delete(); } else { $where = array(); $where[] = array('AND', 'id_sys_object', '=', $id_sys_object_child); $where[] = array('AND', 'field_name', '=', $_POST['sys_field_title'][$relation_id]); $field = new Crud_Models_Field(); $fields = $field->search($where); if (empty($fields)) { continue; } $field = $fields[0]; $subform->id_sys_object_parent = $sys_object->id; $subform->id_sys_object_child = $id_sys_object_child; $subform->id_sys_field = $field->id; $subform->title = $_POST['title'][$relation_id]; $subform->save(); } } } header('location: ' . SITE_ROOT_URI . '/crud/objects/maplist/'); exit; }
<?php $table_name = $control_properties->table_name; $conditional_field_id = $control_properties->conditional_field_id; if (!empty($table_name)) { $sys_object = new Crud_Models_Object(); $sys_object->load($table_name, 'table_name'); $sys_object->loadFieldsForObject(); } else { $sys_field = new Crud_Models_Field(); $sys_field->load($conditional_field_id); $sys_field->loadControl(); $sys_object = new Crud_Models_Object(); $sys_object->load($row->{$sys_field->field_name}); $sys_object->loadFieldsForObject(); } $text_value = ''; if ($value) { $row = new Libraries_Db_Mysql_Model($sys_object->table_name); $row->load($value); if (!$row->isEmpty()) { 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} . ', '; } } } } echo trim($text_value, ', ');
</tr> </thead> <tfoot> <tr> <th>Object</th> <th>Field</th> <th>Relation title</th> <th style="width: 110px;"><i class="fa fa-cogs"></i> Action</th> </tr> </tfoot> <tbody> <?php foreach ($selected_maped_objects as $selected_maped_object) { ?> <?php $field = new Crud_Models_Field(); $field->load($selected_maped_object->id_sys_field); $sys_object = new Crud_Models_Object(); $sys_object->load($selected_maped_object->id_sys_object_child); $sys_object->loadFieldsForObject(); ?> <tr class="form-group"> <td> <div class="ocp-select"> <select name="id_sys_object_child[<?php echo $selected_maped_object->id; ?> ]" class="form-control table-selector"> <option value=""></option> <?php foreach ($maped_objects as $maped_object) {
public function modify($sys_object_id, $row_id = '', $subform_relation_id = null, $subform_relation_value = null) { $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>'; //header('location: ' . SITE_ROOT_URI . '/admin/error/'); exit; } if (!$this->user->role->canExecuteAction('can_view_' . $sys_object->table_name)) { echo '<script>window.location="' . SITE_ROOT_URI . '/admin/error/' . '"</script>'; //header('location: ' . SITE_ROOT_URI . '/admin/error/'); exit; } if ($sys_object->custom_crud_class != '' && new $sys_object->custom_crud_class() instanceof Crud_Interfaces_Crud) { echo call_user_func(array(new $sys_object->custom_crud_class(), 'modify'), $sys_object_id, $row_id); } else { $object_data = new Libraries_Db_Mysql_Model($sys_object->table_name); $subforms = array(); if ($row_id != '') { $object_data->load(intval($row_id)); $where = array(); $where[] = array('AND', 'id_sys_object_parent', '=', $sys_object->id); $subform = new Crud_Models_Subform(); $subforms = $subform->search($where); } if (isset($_GET['clone']) && $_GET['clone'] == 1) { $object_data->id = null; } $subform_relation = null; $subform_relation_field = null; if ($subform_relation_id) { $subform_relation = new Crud_Models_Subform(); $subform_relation->load($subform_relation_id); $subform_relation_field = new Crud_Models_Field(); $subform_relation_field->load($subform_relation->id_sys_field); } Libraries_Event::trigger('beforeFormOpen', $sys_object, $object_data); $user = Admin_Libraries_Admin::getLogedUser()->loadRole(); Libraries_View::getInstance()->sys_object = $sys_object; Libraries_View::getInstance()->object_data = $object_data; Libraries_View::getInstance()->subforms = $subforms; Libraries_View::getInstance()->subform_relation = $subform_relation; Libraries_View::getInstance()->subform_relation_field = $subform_relation_field; Libraries_View::getInstance()->subform_relation_value = $subform_relation_value; Libraries_View::getInstance()->user = $user; $content = Libraries_View::getInstance()->setModule('crud')->load('row'); echo $content; } }
?> </option> <?php } ?> <?php } ?> </select> </div> <?php if (!empty($conditional_field_id)) { ?> <?php $sys_field = new Crud_Models_Field(); $sys_field->load($conditional_field_id); ?> <script> $(document).ready(function() { $('#<?php echo $sys_field->field_name; ?> ').change(function() { var sys_object_id = $(this).val(); $.ajax({ method: "POST", url: "<?php echo SITE_ROOT_URI; ?>
<?php // load maped objects $where = array(); $order = array(); //$where[] = array('AND', 'id', '!=', $parent_sys_object_id); $order[] = array('table_name', 'ASC'); $maped_object = new Crud_Models_Object(); $maped_objects = $maped_object->search($where, $order); $where = array(); $where[] = array('AND', 'id_sys_object', '=', $field->id_sys_object); $where[] = array('AND', 'id', '!=', $field->id); $sys_field = new Crud_Models_Field(); $sys_fields = $sys_field->search($where); ?> <div class="form-group"> <label>Table</label> <div class="ocp-select"> <select class="form-control" name="control-properties-table_name[<?php echo $field->id; ?> ]"> <option value=""></option> <?php foreach ($maped_objects as $maped_object) { ?> <option <?php echo isset($properties->table_name) && $properties->table_name == $maped_object->table_name ? 'selected="selected"' : ''; ?> value="<?php echo $maped_object->table_name;