/** * Public method. Add new activity. */ public function add() { //$GLOBALS['phpgw']->redirect_link('/activitycalendarfrontend/index.php', array('menuaction' => 'activitycalendarfrontend.uiactivity.edit', 'action' => 'new_activity')); $GLOBALS['phpgw']->js->validate_file('json', 'json', 'phpgwapi'); $c = createobject('phpgwapi.config', 'activitycalendarfrontend'); $c->read(); $config = $c->config_data; $ajaxUrl = $c->config_data['AJAXURL']; $categories = $this->so_activity->get_categories(); $targets = $this->so_activity->get_targets(); $offices = $this->so_activity->select_district_list(); $districts = $this->so_activity->get_districts(); $buildings = $this->so_arena->get_buildings(); $arenas = $this->so_arena->get(null, null, 'arena.arena_name', true, null, null, null); $organizations = $this->so_organization->get(null, null, 'org.name', true, null, null, null); $activity = new activitycalendar_activity(); $o_id = phpgw::get_var('organization_id'); $o_id_new = phpgw::get_var('organization_id_hidden'); if (isset($_POST['step_1'])) { //activity shall be registred on a new organization if ($o_id_new == "new_org") { //add new organization to internal activitycalendar organization register $org_homepage = phpgw::get_var('homepage'); if ($org_homepage == 'http://') { $org_homepage = ""; } $org_info['name'] = phpgw::get_var('orgname'); $org_info['orgnr'] = phpgw::get_var('orgno'); $org_info['homepage'] = $org_homepage; $org_info['street'] = phpgw::get_var('address'); $org_info['streetnumber'] = phpgw::get_var('number'); $org_info['zip'] = phpgw::get_var('postzip'); $org_info['postaddress'] = phpgw::get_var('postaddress'); $org_info['status'] = "new"; $o_id = $this->so_activity->add_organization_local($org_info); //add contact persons $contact1 = array(); $contact1['name'] = phpgw::get_var('org_contact1_name'); $contact1['phone'] = phpgw::get_var('org_contact1_phone'); $contact1['mail'] = phpgw::get_var('org_contact1_mail'); $contact1['org_id'] = $o_id; $contact1['group_id'] = 0; $this->so_activity->add_contact_person_local($contact1); $person_arr = $this->so_contact->get_local_contact_persons($o_id); foreach ($person_arr as $p) { $persons[] = $p; } $person_ids = $this->so_organization->get_contacts_local($o_id); $desc = phpgw::get_var('org_description'); $organization = $this->so_organization->get_organization_local($o_id); $new_org = true; $organization = $this->so_organization->get_organization_local($o_id); $person_arr = $this->so_organization->get_contacts_local_as_objects($o_id); foreach ($person_arr as $p) { //var_dump($p); $persons[] = $p; } $message = lang('organization_saved_form'); $this->render('activity_new.php', array('activity' => $activity, 'new_organization' => true, 'organization' => $organization, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl)); } else { $new_org = false; $organization = $this->so_organization->get_single($o_id); $person_arr = $this->so_contact->get(null, null, null, null, null, null, array('organization_id' => $o_id)); foreach ($person_arr as $p) { //var_dump($p); $persons[] = $p; } $activity->set_organization_id($o_id); $activity->set_description($organization->get_description()); $activity->set_contact_persons($pers); $this->render('activity_new.php', array('activity' => $activity, 'new_organization' => false, 'organization' => $organization, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl)); } } else { if (isset($_POST['save_activity'])) { $get_org_from_local = false; $new_org_group = false; $new_org = phpgw::get_var('new_organization'); if ($new_org != null && $new_org == 'yes') { $get_org_from_local = true; } if ($get_org_from_local) { $activity->set_new_org(true); //$person_arr = $this->so_contact->get_local_contact_persons($o_id); //foreach($person_arr as $p) //{ //$persons[] = $p; //} //$person_ids = $this->so_organization->get_contacts_local($o_id); //$desc = $this->so_organization->get_description_local($o_id); $organization = $this->so_organization->get_organization_local($o_id); $new_org = true; //$new_org_group = true; //Add new group for the activity $group_info['name'] = phpgw::get_var('title'); $group_info['organization_id'] = $o_id; $group_info['description'] = phpgw::get_var('description'); $group_info['status'] = "new"; $g_id = $this->so_activity->add_group_local($group_info); //add contact persons $contact1 = array(); $contact1['name'] = phpgw::get_var('contact_name'); $contact1['phone'] = phpgw::get_var('contact_phone'); $contact1['mail'] = phpgw::get_var('contact_mail'); $contact1['org_id'] = $o_id; $contact1['group_id'] = $g_id; $this->so_activity->add_contact_person_local($contact1); $person_arr = $this->so_contact->get_local_contact_persons($g_id, true); foreach ($person_arr as $p) { $persons[] = $p; } $desc = phpgw::get_var('description'); $group = $this->so_group->get_group_local($g_id); $person_ids = $this->so_group->get_contacts_local($g_id); $new_group = true; } else { if (is_numeric($o_id) && $o_id > 0) { $group_info['name'] = phpgw::get_var('title'); $group_info['organization_id'] = $o_id; $group_info['description'] = phpgw::get_var('description'); $group_info['status'] = "new"; $g_id = $this->so_activity->add_group_local($group_info); //add contact persons $contact1 = array(); $contact1['name'] = phpgw::get_var('contact_name'); $contact1['phone'] = phpgw::get_var('contact_phone'); $contact1['mail'] = phpgw::get_var('contact_mail'); $contact1['org_id'] = 0; $contact1['group_id'] = $g_id; $this->so_activity->add_contact_person_local($contact1); $person_arr = $this->so_contact->get_local_contact_persons($g_id, true); foreach ($person_arr as $p) { $persons[] = $p; } $desc = phpgw::get_var('description'); $group = $this->so_group->get_group_local($g_id); $person_ids = $this->so_group->get_contacts_local($g_id); $organization = $this->so_organization->get_single($o_id); $new_group = true; } } if (strlen($desc) > 254) { $desc = substr($desc, 0, 254); } $arena_id = phpgw::get_var('internal_arena_id'); $new_arena = phpgw::get_var('new_arena_hidden'); if ($new_arena != null && $new_arena == 'new_arena') { $arena = new activitycalendar_arena(); $arena_name = phpgw::get_var('arena_name'); $arena_address = phpgw::get_var('arena_address'); $arena_addressnumber = phpgw::get_var('arena_number'); $arena_zip_code = phpgw::get_var('arena_zip_code'); $arena_city = phpgw::get_var('arena_city'); $arena->set_arena_name($arena_name); $arena->set_address($arena_address); $arena->set_addressnumber($arena_addressnumber); $arena->set_zip_code($arena_zip_code); $arena->set_city($arena_city); $arena->set_active(true); // All is good, store arena if ($this->so_arena->store($arena)) { $arena_id = $arena->get_id(); $activity->set_arena($arena_id); } } else { $arena_arr = explode("_", $arena_id); if ($arena_arr[0] == 'i') { $activity->set_internal_arena($arena_arr[1]); } else { $activity->set_arena($arena_arr[1]); } } //... set all parameters $activity->set_title(phpgw::get_var('title')); $activity->set_organization_id($o_id); $activity->set_group_id($g_id); $activity->set_district(phpgw::get_var('district')); $activity->set_office(phpgw::get_var('office')); $activity->set_state(1); $activity->set_category(phpgw::get_var('category')); $target_array = phpgw::get_var('target'); $activity->set_target(implode(",", $target_array)); $activity->set_description($desc); $activity->set_time(phpgw::get_var('time')); $activity->set_contact_persons($persons); $activity->set_special_adaptation(phpgw::get_var('special_adaptation')); $activity->set_contact_person_2_address(phpgw::get_var('contact2_address') . ", " . phpgw::get_var('contact2_number')); $activity->set_contact_person_2_zip(phpgw::get_var('contact2_postaddress')); $activity->set_frontend(true); $activity->set_new_org($new_org); $activity->set_new_group($new_group); $target_ok = false; $district_ok = false; if ($get_org_from_local) { //update new organization with district-id from activity. $this->so_organization->update_org_district_local($organization->get_id(), $activity->get_district()); } if ($activity->get_target() && $activity->get_target() != '') { $target_ok = true; } if ($activity->get_district() && $activity->get_district() != '') { $district_ok = true; } if ($target_ok && $district_ok) { if ($this->so_activity->store($activity)) { // ... and then try to store the object $message = lang('messages_saved_form'); } else { $error = lang('messages_form_error'); } //$org_info_edit_url = self::link('/index.php' ,array('menuaction' => 'activitycalendarfrontend.uiactivity.edit_organization_values')); $GLOBALS['phpgw_info']['flags']['noframework'] = true; $this->render('activity.php', array('activity' => $activity, 'organization' => $organization, 'group' => $group, 'contact1' => $persons[0], 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl)); } else { if (!$target_ok) { $error .= "<br/>" . lang('target_not_selected'); } if (!$district_ok) { $error .= "<br/>" . lang('district_not_selected'); } return $this->render('activity_new.php', array('activity' => $activity, 'organizations' => $organizations, 'organization' => $organization, 'contact1' => $persons[0], 'contact2' => $persons[1], 'org_name' => $org_name, 'new_org' => $new_org, 'groups' => $groups, 'arenas' => $arenas, 'buildings' => $buildings, 'categories' => $categories, 'targets' => $targets, 'districts' => $districts, 'offices' => $offices, 'editable' => true, 'cancel_link' => $cancel_link, 'message' => isset($message) ? $message : phpgw::get_var('message'), 'error' => isset($error) ? $error : phpgw::get_var('error'), 'ajaxURL' => $ajaxUrl)); } } else { return $this->render('activity_new_step_1.php', array('organizations' => $organizations, 'ajaxURL' => $ajaxUrl)); } } }
function get_connected_activities($org_id) { $activities = array(); $sql = "SELECT * FROM activity_activity WHERE organization_id={$org_id}"; $this->db->query($sql, __LINE__, __FILE__); while ($this->db->next_record()) { $activity = new activitycalendar_activity((int) $this->db->f('id')); $activity->set_title($this->unmarshal($this->db->f('title'), 'string')); $activity->set_organization_id($this->unmarshal($this->db->f('organization_id'), 'int')); $activity->set_group_id($this->unmarshal($this->db->f('group_id'), 'int')); $activity->set_district($this->unmarshal($this->db->f('district'), 'int')); $activity->set_office($this->unmarshal($this->db->f('office'), 'int')); $activity->set_category($this->unmarshal($this->db->f('category'), 'int')); $activity->set_state($this->unmarshal($this->db->f('state'), 'int')); $activity->set_target($this->unmarshal($this->db->f('target'), 'string')); $activity->set_description($this->unmarshal($this->db->f('description'), 'string')); $activity->set_arena($this->unmarshal($this->db->f('arena'), 'string')); $activity->set_internal_arena($this->unmarshal($this->db->f('internal_arena'), 'string')); $activity->set_time($this->unmarshal($this->db->f('time'), 'string')); $activity->set_last_change_date($this->unmarshal($this->db->f('last_change_date'), 'int')); $activity->set_special_adaptation($this->unmarshal($this->db->f('special_adaptation', 'bool'))); $activity->set_secret($this->unmarshal($this->db->f('secret'), 'string')); $activity->set_contact_person_2_address($this->unmarshal($this->db->f('contact_person_2_address'), 'string')); $activity->set_contact_person_2_zip($this->unmarshal($this->db->f('contact_person_2_zip'), 'string')); $activity->set_frontend($this->unmarshal($this->db->f('frontend', 'bool'))); $activity->set_new_org($this->unmarshal($this->db->f('new_org', 'bool'))); $activities[] = $activity; } return $activities; }