コード例 #1
0
 function edit_custom_report()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $report_id = array_var($_GET, 'id');
     $report = Reports::getReport($report_id);
     if (!$report->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     if (is_array(array_var($_POST, 'report'))) {
         try {
             ajx_current("empty");
             $report_data = array_var($_POST, 'report');
             DB::beginWork();
             $report->setName($report_data['name']);
             $report->setDescription($report_data['description']);
             $report->setObjectType($report_data['object_type']);
             $report->setOrderBy($report_data['order_by']);
             $report->setIsOrderByAsc($report_data['order_by_asc'] == 'asc');
             $report->save();
             $conditions = array_var($_POST, 'conditions');
             if (!is_array($conditions)) {
                 $conditions = array();
             }
             foreach ($conditions as $condition) {
                 $newCondition = new ReportCondition();
                 if ($condition['id'] > 0) {
                     $newCondition = ReportConditions::getCondition($condition['id']);
                 }
                 if ($condition['deleted'] == "1") {
                     $newCondition->delete();
                     continue;
                 }
                 $newCondition->setReportId($report_id);
                 $custom_prop_id = isset($condition['custom_property_id']) ? $condition['custom_property_id'] : 0;
                 $newCondition->setCustomPropertyId($custom_prop_id);
                 $newCondition->setFieldName($condition['field_name']);
                 $newCondition->setCondition($condition['condition']);
                 if ($condition['field_type'] == 'boolean') {
                     $newCondition->setValue(isset($condition['value']) && $condition['value']);
                 } else {
                     if ($condition['field_type'] == 'date') {
                         if ($condition['value'] == '') {
                             $newCondition->setValue('');
                         } else {
                             $dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condition['value']);
                             $newCondition->setValue(date("m/d/Y", $dtFromWidget->getTimestamp()));
                         }
                     } else {
                         $newCondition->setValue(isset($condition['value']) ? $condition['value'] : '');
                     }
                 }
                 $newCondition->setIsParametrizable(isset($condition['is_parametrizable']));
                 $newCondition->save();
             }
             ReportColumns::delete('report_id = ' . $report_id);
             $columns = array_var($_POST, 'columns');
             asort($columns);
             //sort the array by column order
             foreach ($columns as $column => $order) {
                 if ($order > 0) {
                     $newColumn = new ReportColumn();
                     $newColumn->setReportId($report_id);
                     if (is_numeric($column)) {
                         $newColumn->setCustomPropertyId($column);
                     } else {
                         $newColumn->setFieldName($column);
                     }
                     $newColumn->save();
                 }
             }
             DB::commit();
             flash_success(lang('custom report updated'));
             ajx_current('back');
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     } else {
         $this->setTemplate('add_custom_report');
         tpl_assign('url', get_url('reporting', 'edit_custom_report', array('id' => $report_id)));
         if ($report instanceof Report) {
             tpl_assign('id', $report_id);
             $report_data = array('name' => $report->getName(), 'description' => $report->getDescription(), 'object_type' => $report->getObjectType(), 'order_by' => $report->getOrderBy(), 'order_by_asc' => $report->getIsOrderByAsc(), 'workspace' => $report->getWorkspace(), 'tags' => $report->getTags());
             tpl_assign('report_data', $report_data);
             $conditions = ReportConditions::getAllReportConditions($report_id);
             tpl_assign('conditions', $conditions);
             $columns = ReportColumns::getAllReportColumns($report_id);
             $colIds = array();
             foreach ($columns as $col) {
                 if ($col->getCustomPropertyId() > 0) {
                     $colIds[] = $col->getCustomPropertyId();
                 } else {
                     $colIds[] = $col->getFieldName();
                 }
             }
             tpl_assign('columns', $colIds);
         }
         $selected_type = $report->getObjectType();
         $types = array(array("", lang("select one")), array("Companies", lang("companies")), array("Contacts", lang("contacts")), array("MailContents", lang("email type")), array("ProjectEvents", lang("events")), array("ProjectFiles", lang("file")), array("ProjectMilestones", lang("milestone")), array("ProjectMessages", lang("message")), array("ProjectTasks", lang("task")), array("Users", lang("user")), array("ProjectWebpages", lang("webpage")), array("Projects", lang("workspace")));
         tpl_assign('object_types', $types);
         tpl_assign('selected_type', $selected_type);
         tpl_assign('allowed_columns', $this->get_allowed_columns($selected_type), true);
     }
 }
コード例 #2
0
 function edit_custom_report()
 {
     if (logged_user()->isGuest()) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $report_id = array_var($_GET, 'id');
     $report = Reports::getReport($report_id);
     if (!$report->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     if (is_array(array_var($_POST, 'report'))) {
         try {
             ajx_current("empty");
             $report_data = array_var($_POST, 'report');
             $member_ids = json_decode(array_var($_POST, 'members'));
             if (!is_array($member_ids) || count($member_ids) == 0) {
                 flash_error(lang('must choose at least one member'));
                 ajx_current("empty");
                 return;
             }
             $members = Members::findAll(array("conditions" => array("`id` IN(?)", $member_ids)));
             DB::beginWork();
             $report->setObjectName($report_data['name']);
             $report->setDescription($report_data['description']);
             $report->setReportObjectTypeId($report_data['report_object_type_id']);
             $report->setOrderBy($report_data['order_by']);
             $report->setIsOrderByAsc($report_data['order_by_asc'] == 'asc');
             $report->save();
             $conditions = array_var($_POST, 'conditions');
             if (!is_array($conditions)) {
                 $conditions = array();
             }
             foreach ($conditions as $condition) {
                 $newCondition = new ReportCondition();
                 if ($condition['id'] > 0) {
                     $newCondition = ReportConditions::getCondition($condition['id']);
                 }
                 if ($condition['deleted'] == "1") {
                     $newCondition->delete();
                     continue;
                 }
                 $newCondition->setReportId($report_id);
                 $custom_prop_id = isset($condition['custom_property_id']) ? $condition['custom_property_id'] : 0;
                 $newCondition->setCustomPropertyId($custom_prop_id);
                 $newCondition->setFieldName($condition['field_name']);
                 $newCondition->setCondition($condition['condition']);
                 if ($condition['field_type'] == 'boolean') {
                     $newCondition->setValue(isset($condition['value']) && $condition['value']);
                 } else {
                     if ($condition['field_type'] == 'date') {
                         if ($condition['value'] == '') {
                             $newCondition->setValue('');
                         } else {
                             $dtFromWidget = DateTimeValueLib::dateFromFormatAndString(user_config_option('date_format'), $condition['value']);
                             $newCondition->setValue(date("m/d/Y", $dtFromWidget->getTimestamp()));
                         }
                     } else {
                         $newCondition->setValue(isset($condition['value']) ? $condition['value'] : '');
                     }
                 }
                 $newCondition->setIsParametrizable(isset($condition['is_parametrizable']));
                 $newCondition->save();
             }
             ReportColumns::delete('report_id = ' . $report_id);
             $columns = array_var($_POST, 'columns');
             asort($columns);
             //sort the array by column order
             foreach ($columns as $column => $order) {
                 if ($order > 0) {
                     $newColumn = new ReportColumn();
                     $newColumn->setReportId($report_id);
                     if (is_numeric($column)) {
                         $newColumn->setCustomPropertyId($column);
                     } else {
                         $newColumn->setFieldName($column);
                     }
                     $newColumn->save();
                 }
             }
             $object_controller = new ObjectController();
             $object_controller->add_to_members($report, $member_ids);
             DB::commit();
             flash_success(lang('custom report updated'));
             ajx_current('back');
         } catch (Exception $e) {
             DB::rollback();
             flash_error($e->getMessage());
             ajx_current("empty");
         }
         // try
     } else {
         $this->setTemplate('add_custom_report');
         tpl_assign('url', get_url('reporting', 'edit_custom_report', array('id' => $report_id)));
         if ($report instanceof Report) {
             tpl_assign('id', $report_id);
             $report_data = array('name' => $report->getObjectName(), 'description' => $report->getDescription(), 'report_object_type_id' => $report->getReportObjectTypeId(), 'order_by' => $report->getOrderBy(), 'order_by_asc' => $report->getIsOrderByAsc());
             tpl_assign('report_data', $report_data);
             $conditions = ReportConditions::getAllReportConditions($report_id);
             tpl_assign('conditions', $conditions);
             $columns = ReportColumns::getAllReportColumns($report_id);
             $colIds = array();
             foreach ($columns as $col) {
                 if ($col->getCustomPropertyId() > 0) {
                     $colIds[] = $col->getCustomPropertyId();
                 } else {
                     $colIds[] = $col->getFieldName();
                 }
             }
             tpl_assign('columns', $colIds);
         }
         $selected_type = $report->getReportObjectTypeId();
         $types = array(array("", lang("select one")));
         $object_types = ObjectTypes::getAvailableObjectTypes();
         foreach ($object_types as $ot) {
             $types[] = array($ot->getId(), lang($ot->getName()));
         }
         tpl_assign('object_types', $types);
         tpl_assign('selected_type', $selected_type);
         tpl_assign('object', $report);
         tpl_assign('allowed_columns', $this->get_allowed_columns($selected_type), true);
     }
 }