false, 'actual_letter' => null, 'actual_max_contacts' => null, 'request_from' => null ); var $public_functions = array( 'index' => true, 'change_max_results' => true, 'change_catalog' => true, 'delete_contacts' => true, 'change_letter' => true, 'choose_contact' => true, 'init_cc' => true ); var $template; /** * Construtor... * */ public function ui_mobilecc() { $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); $this->bo = CreateObject('mobile.bo_mobilecc'); $page_info = $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile'); if($page_info) { $this->page_info = $page_info; } else { $this->set_page_info_to_default(); } //if() } private function set_page_info_to_default() { //Valores default para iniciar o módulo de contatos $this->page_info['actual_catalog'] = 'bo_people_catalog'; $this->page_info['actual_letter'] = 'a'; $this->page_info['actual_max_contacts'] = 10; $this->page_info['request_from'] = null; } private function save_session() { $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile',$this->page_info); } public function index($params) { $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]); $this->contacts_list(); } public function change_max_results($params) { $this->page_info['actual_max_contacts'] = $params['results']; $this->contacts_list(); $this->save_session(); } public function change_letter($params) { $this->page_info['actual_letter'] = $params['letter']; $this->page_info['actual_max_contacts'] = 10; $this->contacts_list(); $this->save_session(); } public function change_catalog($params) { $this->page_info['actual_catalog'] = $params['catalog']; $this->page_info['actual_max_contacts'] = 10; $this->page_info['actual_letter'] = 'a'; $this->contacts_list(); $this->save_session(); } /** * Função de inicio do módulo para escolha de um contato para outro módulo. * * @return * @param $params Object */ public function choose_contact($params) { $this->set_page_info_to_default(); $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from $this->contacts_list(); $this->save_session(); } /** * Função de inicio do módulo de cc * * @return * @param $params Object */ public function init_cc($params) { $this->set_page_info_to_default(); $this->contacts_list(); $this->save_session(); } /** * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita * busca, mostra apenas o formulário para pesquisa. * * @return */ function contacts_list() { $this->template->set_file( Array( 'contacts_list' => 'cc_main.tpl' ) ); $this->template->set_block("contacts_list","catalog_row"); $this->template->set_block("contacts_list","main_body"); $this->template->set_block("contacts_list","pagging_block"); //Langs gerais da página $this->template->set_var("lang_back",lang("back")); $this->template->set_var("lang_more",lang("more")); $this->template->set_var("lang_contacts",ucfirst(lang("contacts"))); $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]); $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10); //Combo de catálogos $catalogs = $this->bo->get_all_catalogs(); foreach($catalogs as $catalog) { $this->template->set_var("catalog_value",$catalog["catalog"]); $this->template->set_var("catalog_name",$catalog["label"]); if($this->page_info['actual_catalog']==$catalog['catalog']) $this->template->set_var("selected","selected"); else $this->template->set_var("selected"," "); $this->template->fp("catalogs","catalog_row",true); } $this->bo->set_catalog($this->page_info["actual_catalog"]); $contacts = $this->bo->search($this->page_info["actual_letter"]."%", $this->page_info["actual_max_contacts"]); //Letras da paginação $max_letters = 5; if ( in_array($this->page_info['actual_letter'], range("a","c"))){ //Letras de A à C iniciam sempre com A $this->template->set_var('show_back','none'); $this->template->set_var('show_next','inline'); $first_letter = "a"; $this->template->set_var('href_next',"index.php?menuaction=mobile.". "ui_mobilecc.change_letter&letter=f"); } else if ( in_array($this->page_info['actual_letter'], range("x","z"))) { //Letras de X à Z terminam sempre no Z $this->template->set_var('show_back','inline'); $this->template->set_var('show_next','none'); $first_letter = "v"; $this->template->set_var('href_back',"index.php?menuaction=mobile.". "ui_mobilecc.change_letter&letter=u"); } else { //Letras do meio $this->template->set_var('show_back','inline'); $this->template->set_var('show_next','inline'); $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter $this->template->set_var('href_back',"index.php?menuaction=mobile.". "ui_mobilecc.change_letter&letter=".$first_letter); $this->template->set_var('href_next',"index.php?menuaction=mobile.". "ui_mobilecc.change_letter&letter=".$last_letter); $first_letter++; } for($i=1;$i<=$max_letters;$i++) { //Roda as letras $this->template->set_var("href","index.php?menuaction=mobile.". "ui_mobilecc.change_letter&letter=".$first_letter); $this->template->set_var("letter",strtoupper($first_letter)); if($first_letter===$this->page_info["actual_letter"]) $this->template->set_var("class_button","letter-contact-selected"); else $this->template->set_var("class_button","btn_off"); $this->template->set_var("letter",strtoupper($first_letter)); $this->template->fp("pagging_letters","pagging_block",true); $first_letter++; } if($contacts['has_more']) $this->template->set_var("show_more","block"); else $this->template->set_var("show_more","none"); unset($contacts['has_more']); $this->template->set_var("contacts",$this->print_contacts($contacts,true,$this->page_info['request_from'])); $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body')); } /** * Remove os contatos selecionados * * @return * @param $contacts Object * @param $show_checkbox Object[optional] */ function delete_contacts($params) { $this->bo->set_catalog($params['catalog']); $status = $this->bo->remove_multiple_entries($params['contacts']); $type = $this->page_info['actual_catalog']==='bo_people_catalog'?"contacts":"groups"; if($status['success']) header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully")); else header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed")); } static function print_contacts($contacts,$show_checkbox=false,$request_from = null) { $functions = CreateObject('mobile.common_functions'); $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); $p->set_file( Array( 'cc_t' => 'contacts_list.tpl' ) ); $p->set_block('cc_t', 'rows_contacts'); $p->set_block('cc_t', 'row_contacts'); $p->set_block('cc_t', 'row_groups'); $p->set_block('cc_t', 'no_contacts'); $bg = "par"; if(!empty($contacts)) { foreach($contacts as $id => $contact) { $p->set_var('show_check',$show_checkbox?"inline":"none"); $p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par"); if($contact["catalog"]!=="bo_group_manager") { //Contatos $id=$contact["catalog"]==="bo_people_catalog"?$contact["id_contact"]:$contact['uidnumber'][0]; $mail = $contact["connections"]["connection1"]["connection_value"];//Preciso o mail depois $cn = is_array($contact["names_ordered"])? $contact["names_ordered"][0]:$contact["names_ordered"]; if(($contact["connections"]["connection1"]["connection_value"]==null || $contact["connections"]["connection1"]["id_type"]!=="1") && isset($request_from)) //Se vier de outro módulo e não possuir e-mail, não mostre. continue; $p->set_var('contact_id',$id); $p->set_var('lang_tel',lang("tel")); $p->set_var('show_tel',$contact["connections"]["connection2"]["connection_value"]!=null?"inline":"none"); $p->set_var('contact_name',$functions->strach_string($cn,17)); $p->set_var('email', $functions->strach_string( ($contact["connections"]["connection1"]["connection_value"]!=null && $contact["connections"]["connection1"]["id_type"]==="1")? $contact["connections"]["connection1"]["connection_value"]:" ",20)); $p->set_var('tel',$functions->strach_string($contact["connections"]["connection1"]["id_type"]==="2"? $contact["connections"]["connection1"]["connection_value"]: $contact["connections"]["connection2"]["connection_value"],19)); $p->fp('rows','row_contacts',True); } else { //Grupos $id=$contact["id_group"]; $mail = $cn = $contact["title"]; $p->set_var('group_id',$contact["id_group"]); $p->set_var('group_name',$contact["title"]); $p->fp('rows','row_groups',True); } if($request_from==null) { $p->set_var('lang_see_details',strtoupper(lang("see details"))); $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".$contact["catalog"]); } else { $p->set_var('lang_see_details',strtoupper(lang("select"))); $p->set_var('href_details','ui_mobilemail.add_recipient&mail=$mail&cn=$cn'); } } } else { $p->set_var("lang_no_results",lang("no results found")); $p->parse("rows","no_contacts"); } return $p->fp('out','rows_contacts'); } } ?>