public function edit()
 {
     $procedure_id = phpgw::get_var('id');
     if (isset($procedure_id) && $procedure_id > 0) {
         $procedure = $this->so->get_single($procedure_id);
     } else {
         $procedure = new controller_procedure();
     }
     if (isset($_POST['save_procedure'])) {
         //var_dump($_POST);
         //var_dump(strtotime(phpgw::get_var('start_date')));
         //die;
         if (!$this->add && !$this->edit) {
             phpgwapi_cache::message_set('No access', 'error');
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.view', 'id' => $procedure_id));
         }
         if (isset($procedure)) {
             $description_txt = phpgw::get_var('description', 'html');
             $description_txt = str_replace(" ", " ", $description_txt);
             $purpose_txt = phpgw::get_var('purpose', 'html');
             $purpose_txt = str_replace(" ", " ", $purpose_txt);
             $reference_txt = phpgw::get_var('reference', 'html');
             $reference_txt = str_replace(" ", " ", $reference_txt);
             $responsibility_txt = phpgw::get_var('responsibility', 'html');
             $responsibility_txt = str_replace(" ", " ", $responsibility_txt);
             $procedure->set_title(phpgw::get_var('title'));
             $procedure->set_purpose($purpose_txt);
             $procedure->set_responsibility($responsibility_txt);
             $procedure->set_description($description_txt);
             $procedure->set_reference($reference_txt);
             $procedure->set_attachment(phpgw::get_var('attachment'));
             $procedure->set_start_date(strtotime(phpgw::get_var('start_date')));
             $procedure->set_end_date(strtotime(phpgw::get_var('end_date')));
             $procedure->set_revision_date(strtotime(phpgw::get_var('revision_date')));
             $procedure->set_control_area_id(phpgw::get_var('control_area'));
             $revision = (int) $procedure->get_revision_no();
             if ($revision && is_numeric($revision) && $revision > 0) {
                 $procedure->set_revision_no($revision);
             } else {
                 $procedure->set_revision_no(1);
             }
             if (isset($procedure_id) && $procedure_id > 0) {
                 $proc_id = $procedure_id;
                 if ($this->so->store($procedure)) {
                     $message = lang('messages_saved_form');
                 } else {
                     $error = lang('messages_form_error');
                 }
             } else {
                 $proc_id = $this->so->add($procedure);
                 if ($proc_id) {
                     $message = lang('messages_saved_form');
                 } else {
                     $error = lang('messages_form_error');
                 }
             }
             $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.view', 'id' => $proc_id));
         }
     } else {
         if (isset($_POST['revisit_procedure'])) {
             if (!$this->add && !$this->edit) {
                 phpgwapi_cache::message_set('No access', 'error');
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.view', 'id' => $procedure_id));
             }
             $old_procedure = $this->so->get_single($procedure_id);
             if (isset($procedure)) {
                 $revision = (int) $procedure->get_revision_no();
                 if ($revision && is_numeric($revision)) {
                     $revision++;
                     $procedure->set_revision_no($revision);
                 } else {
                     $procedure->set_revision_no(2);
                 }
                 $description_txt = phpgw::get_var('description', 'html');
                 $description_txt = str_replace(" ", " ", $description_txt);
                 $purpose_txt = phpgw::get_var('purpose', 'html');
                 $purpose_txt = str_replace(" ", " ", $purpose_txt);
                 $reference_txt = phpgw::get_var('reference', 'html');
                 $reference_txt = str_replace(" ", " ", $reference_txt);
                 $procedure->set_title(phpgw::get_var('title'));
                 $procedure->set_purpose($purpose_txt);
                 $procedure->set_responsibility(phpgw::get_var('responsibility'));
                 $procedure->set_description($description_txt);
                 $procedure->set_reference($reference_txt);
                 $procedure->set_attachment(phpgw::get_var('attachment'));
                 $procedure->set_start_date(strtotime(phpgw::get_var('start_date')));
                 $procedure->set_end_date(strtotime(phpgw::get_var('end_date')));
                 $procedure->set_control_area_id(phpgw::get_var('control_area'));
                 if (isset($procedure_id) && $procedure_id > 0) {
                     $proc_id = $procedure_id;
                     $old_procedure->set_id(null);
                     $old_procedure->set_end_date(time());
                     $old_procedure->set_procedure_id($proc_id);
                     if ($this->so->add($old_procedure)) {
                         if ($this->so->store($procedure)) {
                             $message = lang('messages_saved_form');
                         } else {
                             $error = lang('messages_form_error');
                         }
                     }
                 }
                 $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.view', 'id' => $proc_id));
             }
         } else {
             if (isset($_POST['cancel_procedure'])) {
                 if (isset($procedure_id) && $procedure_id > 0) {
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.view', 'id' => $procedure_id));
                 } else {
                     $GLOBALS['phpgw']->redirect_link('/index.php', array('menuaction' => 'controller.uiprocedure.index'));
                 }
             } else {
                 if ($this->flash_msgs) {
                     $msgbox_data = $GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
                     $msgbox_data = $GLOBALS['phpgw']->common->msgbox($msgbox_data);
                 }
                 // Sigurd: START as categories
                 $cats = CreateObject('phpgwapi.categories', -1, 'controller', '.control');
                 $cats->supress_info = true;
                 $control_areas = $cats->formatted_xslt_list(array('format' => 'filter', 'selected' => $procedure->get_control_area_id(), 'globals' => true, 'use_acl' => $this->_category_acl));
                 array_unshift($control_areas['cat_list'], array('cat_id' => '', 'name' => lang('select value')));
                 $control_areas_array2 = array();
                 //_debug_array($control_areas);
                 foreach ($control_areas['cat_list'] as $cat_list) {
                     if ($cat_list['cat_id'] == $procedure->get_control_area_id()) {
                         $control_areas_array2[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name'], 'selected' => 1);
                     } else {
                         $control_areas_array2[] = array('id' => $cat_list['cat_id'], 'name' => $cat_list['name']);
                     }
                 }
                 // END as categories
                 /*				$control_area_array = $this->so_control_area->get_control_area_array();
                 				foreach ($control_area_array as $control_area)
                 				{
                 					if($procedure->get_control_area_id() && $control_area->get_id() == $procedure->get_control_area_id())
                 					{
                 						$control_area_options[] = array
                 						(
                 							'id'	=> $control_area->get_id(),
                 							'name'	=> $control_area->get_title(),
                 							'selected' => 'yes'
                 						);
                 					}
                 					else
                 					{
                 						$control_area_options[] = array
                 						(
                 							'id'	=> $control_area->get_id(),
                 							'name'	=> $control_area->get_title()
                 						);
                 					}
                 				}
                 */
                 /*
                  * hack to fix display of   char 
                  */
                 $procedure->set_description(str_replace(" ", " ", $procedure->get_description()));
                 $procedure->set_responsibility(str_replace(' ', ' ', $procedure->get_responsibility()));
                 $procedure->set_reference(str_replace(' ', ' ', $procedure->get_reference()));
                 $procedure_array = $procedure->toArray();
                 //_debug_array($procedure_array);
                 $tabs = array(array('label' => lang('Procedure')), array('label' => lang('View_documents_for_procedure')));
                 $GLOBALS['phpgw']->jqcal->add_listener('start_date');
                 $GLOBALS['phpgw']->jqcal->add_listener('end_date');
                 $GLOBALS['phpgw']->jqcal->add_listener('revision_date');
                 $end_date = date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], $procedure->get_end_date() ? $procedure->get_end_date() : '');
                 $revision_date = date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], $procedure->get_revision_date() ? $procedure->get_revision_date() : '');
                 $data = array('tabs' => $GLOBALS['phpgw']->common->create_tabs($tabs, 0), 'view' => "view_procedure", 'value_id' => !empty($procedure) ? $procedure->get_id() : 0, 'start_date' => date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], $procedure->get_start_date() ? $procedure->get_start_date() : time()), 'end_date' => $end_date ? $end_date : '', 'revision_date' => $revision_date ? $revision_date : '', 'editable' => true, 'procedure' => $procedure_array, 'control_area' => array('options' => $control_areas_array2));
                 $GLOBALS['phpgw_info']['flags']['app_header'] = lang('controller') . '::' . lang('Procedure');
                 $this->use_yui_editor(array('responsibility', 'description', 'reference'));
                 self::render_template_xsl(array('procedure/procedure_tabs', 'procedure/procedure_item'), $data);
             }
         }
     }
 }
 function populate(int $procedure_id, &$procedure)
 {
     if ($procedure == null) {
         $procedure = new controller_procedure((int) $procedure_id);
         $procedure->set_title($this->unmarshal($this->db->f('title'), 'string'));
         $procedure->set_purpose($this->unmarshal($this->db->f('purpose'), 'string'));
         $procedure->set_responsibility($this->unmarshal($this->db->f('responsibility'), 'string'));
         $procedure->set_description($this->unmarshal($this->db->f('description'), 'string'));
         $procedure->set_reference($this->unmarshal($this->db->f('reference'), 'string'));
         $procedure->set_attachment($this->unmarshal($this->db->f('attachment'), 'string'));
         $procedure->set_start_date($this->unmarshal($this->db->f('start_date'), 'int'));
         $procedure->set_end_date($this->unmarshal($this->db->f('end_date'), 'int'));
         $procedure->set_procedure_id($this->unmarshal($this->db->f('procedure_id'), 'int'));
         $procedure->set_revision_no($this->unmarshal($this->db->f('revision_no'), 'int'));
         $procedure->set_revision_date($this->unmarshal($this->db->f('revision_date'), 'int'));
         $procedure->set_control_area_id($this->unmarshal($this->db->f('control_area_id', 'int')));
         //$procedure->set_control_area_name($this->unmarshal($this->db->f('control_area_name', 'string')));
         $category = execMethod('phpgwapi.categories.return_single', $this->unmarshal($this->db->f('control_area_id', 'int')));
         $procedure->set_control_area_name($category[0]['name']);
     }
     return $procedure;
 }