[480] | 1 | <?php |
---|
| 2 | class ui_mobilecc{ |
---|
| 3 | |
---|
| 4 | var $nextmatchs; |
---|
[1474] | 5 | var $bo; |
---|
[480] | 6 | var $page_info = array ( |
---|
[527] | 7 | 'actual_catalog' => false, |
---|
[3595] | 8 | 'actual_letter' => null, |
---|
| 9 | 'actual_max_contacts' => null, |
---|
| 10 | 'request_from' => null |
---|
[480] | 11 | ); |
---|
| 12 | |
---|
| 13 | var $public_functions = array( |
---|
[3595] | 14 | 'index' => true, |
---|
| 15 | 'change_max_results' => true, |
---|
| 16 | 'change_catalog' => true, |
---|
| 17 | 'delete_contacts' => true, |
---|
| 18 | 'change_letter' => true, |
---|
| 19 | 'choose_contact' => true, |
---|
[3630] | 20 | 'init_cc' => true, |
---|
| 21 | 'contact_view' => true, |
---|
| 22 | 'contact_add_edit' => true, |
---|
| 23 | 'contact_add' => true, |
---|
| 24 | 'contact_edit' => true |
---|
[480] | 25 | ); |
---|
[3595] | 26 | var $template; |
---|
[480] | 27 | |
---|
[527] | 28 | /** |
---|
| 29 | * Construtor... |
---|
| 30 | * |
---|
| 31 | */ |
---|
| 32 | public function ui_mobilecc() { |
---|
[3595] | 33 | $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
| 34 | $this->bo = CreateObject('mobile.bo_mobilecc'); |
---|
| 35 | $page_info = $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile'); |
---|
| 36 | |
---|
| 37 | if($page_info) { |
---|
| 38 | $this->page_info = $page_info; |
---|
| 39 | } |
---|
| 40 | else { |
---|
| 41 | $this->set_page_info_to_default(); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | //if() |
---|
| 45 | |
---|
[480] | 46 | } |
---|
| 47 | |
---|
[3595] | 48 | private function set_page_info_to_default() { //Valores default para iniciar o módulo de contatos |
---|
| 49 | $this->page_info['actual_catalog'] = 'bo_people_catalog'; |
---|
| 50 | $this->page_info['actual_letter'] = 'a'; |
---|
| 51 | $this->page_info['actual_max_contacts'] = 10; |
---|
| 52 | $this->page_info['request_from'] = null; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | private function save_session() { |
---|
| 56 | $GLOBALS['phpgw']->session->appsession('mobilecc.page_info','mobile',$this->page_info); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | public function index($params) { |
---|
| 60 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]); |
---|
| 61 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]); |
---|
| 62 | $this->contacts_list(); |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | public function change_max_results($params) { |
---|
| 66 | $this->page_info['actual_max_contacts'] = $params['results']; |
---|
| 67 | $this->contacts_list(); |
---|
| 68 | $this->save_session(); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public function change_letter($params) { |
---|
| 72 | $this->page_info['actual_letter'] = $params['letter']; |
---|
| 73 | $this->page_info['actual_max_contacts'] = 10; |
---|
| 74 | $this->contacts_list(); |
---|
| 75 | $this->save_session(); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | public function change_catalog($params) { |
---|
| 79 | |
---|
[3820] | 80 | if( $params['catalog'] ) $this->page_info['actual_catalog'] = $params['catalog']; |
---|
[3595] | 81 | $this->page_info['actual_max_contacts'] = 10; |
---|
| 82 | $this->page_info['actual_letter'] = 'a'; |
---|
| 83 | |
---|
[3820] | 84 | $this->contacts_list($params); |
---|
[3595] | 85 | |
---|
| 86 | $this->save_session(); |
---|
| 87 | } |
---|
| 88 | |
---|
[527] | 89 | /** |
---|
[3595] | 90 | * Função de inicio do módulo para escolha de um contato para outro módulo. |
---|
| 91 | * |
---|
[527] | 92 | * @return |
---|
[3595] | 93 | * @param $params Object |
---|
[527] | 94 | */ |
---|
[3595] | 95 | public function choose_contact($params) { |
---|
| 96 | $this->set_page_info_to_default(); |
---|
| 97 | $this->page_info['request_from'] = $params['request_from']; //Para escolher contato vindo de outro modulo, mudo apenas o request_from |
---|
| 98 | $this->contacts_list(); |
---|
| 99 | $this->save_session(); |
---|
[480] | 100 | } |
---|
| 101 | |
---|
[527] | 102 | /** |
---|
[3595] | 103 | * Função de inicio do módulo de cc |
---|
[527] | 104 | * |
---|
[3595] | 105 | * @return |
---|
| 106 | * @param $params Object |
---|
[527] | 107 | */ |
---|
[3595] | 108 | public function init_cc($params) { |
---|
| 109 | $this->set_page_info_to_default(); |
---|
[3820] | 110 | $this->contacts_list($params); |
---|
[3595] | 111 | $this->save_session(); |
---|
[480] | 112 | } |
---|
[527] | 113 | |
---|
| 114 | /** |
---|
| 115 | * Monta a lista de contatos na tela, de acordo com a busca. Se não foi feita |
---|
| 116 | * busca, mostra apenas o formulário para pesquisa. |
---|
| 117 | * |
---|
| 118 | * @return |
---|
| 119 | */ |
---|
| 120 | |
---|
[3820] | 121 | function contacts_list($params) { |
---|
[527] | 122 | |
---|
[3595] | 123 | $this->template->set_file( |
---|
| 124 | Array( |
---|
[3641] | 125 | 'contacts_list' => 'cc_main.tpl', |
---|
| 126 | 'home_search_bar' => 'search_bar.tpl' |
---|
[3595] | 127 | ) |
---|
| 128 | ); |
---|
| 129 | $this->template->set_block("contacts_list","catalog_row"); |
---|
| 130 | $this->template->set_block("contacts_list","main_body"); |
---|
| 131 | $this->template->set_block("contacts_list","pagging_block"); |
---|
[3641] | 132 | $this->template->set_block('home_search_bar','search_bar'); |
---|
[480] | 133 | |
---|
[3595] | 134 | //Langs gerais da página |
---|
| 135 | $this->template->set_var("lang_back",lang("back")); |
---|
[3710] | 136 | $this->template->set_var("selecteds",ucfirst(lang("selecteds"))); |
---|
[3595] | 137 | $this->template->set_var("lang_more",lang("more")); |
---|
[3605] | 138 | $this->template->set_var("lang_search",lang("search")); |
---|
[3595] | 139 | $this->template->set_var("lang_contacts",ucfirst(lang("contacts"))); |
---|
| 140 | $this->template->set_var("actual_catalog",$this->page_info["actual_catalog"]); |
---|
| 141 | $this->template->set_var("next_max_results",$this->page_info["actual_max_contacts"]+10); |
---|
[3821] | 142 | |
---|
| 143 | $show_checkbox = true; |
---|
| 144 | if(strpos($this->page_info["actual_catalog"],"ldap")===false) { |
---|
| 145 | $this->template->set_var("show_actions", "block"); |
---|
| 146 | } else { |
---|
| 147 | $this->template->set_var("show_actions", "none"); |
---|
| 148 | $show_checkbox = false; |
---|
| 149 | } |
---|
| 150 | |
---|
[3820] | 151 | $this->template->set_var("show_add_button",$this->page_info["actual_catalog"] == "bo_group_manager" ? "none" : ""); |
---|
| 152 | |
---|
[3596] | 153 | $this->template->set_var("contacts_request_from", |
---|
| 154 | $this->page_info["request_from"]==null? |
---|
| 155 | "none":$this->page_info["request_from"]); |
---|
[527] | 156 | |
---|
[3731] | 157 | if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile')!="mini_desktop") |
---|
| 158 | $this->template->set_var('search',$this->template->fp('out','search_bar')); |
---|
[3641] | 159 | |
---|
[3595] | 160 | //Combo de catálogos |
---|
| 161 | $catalogs = $this->bo->get_all_catalogs(); |
---|
| 162 | foreach($catalogs as $catalog) { |
---|
| 163 | $this->template->set_var("catalog_value",$catalog["catalog"]); |
---|
| 164 | $this->template->set_var("catalog_name",$catalog["label"]); |
---|
| 165 | if($this->page_info['actual_catalog']==$catalog['catalog']) |
---|
| 166 | $this->template->set_var("selected","selected"); |
---|
[527] | 167 | else |
---|
[3595] | 168 | $this->template->set_var("selected"," "); |
---|
| 169 | $this->template->fp("catalogs","catalog_row",true); |
---|
[527] | 170 | } |
---|
[3595] | 171 | $this->bo->set_catalog($this->page_info["actual_catalog"]); |
---|
| 172 | $contacts = $this->bo->search($this->page_info["actual_letter"]."%", |
---|
| 173 | $this->page_info["actual_max_contacts"]); |
---|
| 174 | |
---|
[527] | 175 | |
---|
[3595] | 176 | //Letras da paginação |
---|
| 177 | $max_letters = 5; |
---|
| 178 | if ( in_array($this->page_info['actual_letter'], |
---|
| 179 | range("a","c"))){ //Letras de A à C iniciam sempre com A |
---|
| 180 | |
---|
| 181 | $this->template->set_var('show_back','none'); |
---|
| 182 | $this->template->set_var('show_next','inline'); |
---|
| 183 | $first_letter = "a"; |
---|
| 184 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
| 185 | "ui_mobilecc.change_letter&letter=f"); |
---|
[527] | 186 | } |
---|
[3595] | 187 | else if ( in_array($this->page_info['actual_letter'], |
---|
| 188 | range("x","z"))) { //Letras de X à Z terminam sempre no Z |
---|
| 189 | $this->template->set_var('show_back','inline'); |
---|
| 190 | $this->template->set_var('show_next','none'); |
---|
| 191 | $first_letter = "v"; |
---|
| 192 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
| 193 | "ui_mobilecc.change_letter&letter=u"); |
---|
[480] | 194 | } |
---|
[3595] | 195 | else { //Letras do meio |
---|
| 196 | $this->template->set_var('show_back','inline'); |
---|
| 197 | $this->template->set_var('show_next','inline'); |
---|
[588] | 198 | |
---|
[3595] | 199 | $first_letter = chr(ord($this->page_info["actual_letter"])-3);//Inicio 3 letras antes |
---|
| 200 | $last_letter = chr(ord($first_letter)+($max_letters+1));//A ultima é a máxima quantidade de letras mais 1 do next_letter |
---|
| 201 | |
---|
| 202 | $this->template->set_var('href_back',"index.php?menuaction=mobile.". |
---|
| 203 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
| 204 | $this->template->set_var('href_next',"index.php?menuaction=mobile.". |
---|
| 205 | "ui_mobilecc.change_letter&letter=".$last_letter); |
---|
| 206 | $first_letter++; |
---|
[480] | 207 | } |
---|
| 208 | |
---|
[3595] | 209 | for($i=1;$i<=$max_letters;$i++) { //Roda as letras |
---|
| 210 | $this->template->set_var("href","index.php?menuaction=mobile.". |
---|
| 211 | "ui_mobilecc.change_letter&letter=".$first_letter); |
---|
| 212 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
| 213 | if($first_letter===$this->page_info["actual_letter"]) |
---|
| 214 | $this->template->set_var("class_button","letter-contact-selected"); |
---|
[1474] | 215 | else |
---|
[3595] | 216 | $this->template->set_var("class_button","btn_off"); |
---|
| 217 | $this->template->set_var("letter",strtoupper($first_letter)); |
---|
| 218 | $this->template->fp("pagging_letters","pagging_block",true); |
---|
| 219 | $first_letter++; |
---|
[588] | 220 | } |
---|
| 221 | |
---|
[3595] | 222 | |
---|
| 223 | if($contacts['has_more']) |
---|
| 224 | $this->template->set_var("show_more","block"); |
---|
| 225 | else |
---|
| 226 | $this->template->set_var("show_more","none"); |
---|
| 227 | unset($contacts['has_more']); |
---|
| 228 | |
---|
[3821] | 229 | $this->template->set_var("contacts",$this->print_contacts($contacts,$show_checkbox,$this->page_info['request_from'])); |
---|
[480] | 230 | |
---|
[3595] | 231 | |
---|
| 232 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','main_body')); |
---|
[480] | 233 | } |
---|
| 234 | |
---|
[3595] | 235 | /** |
---|
| 236 | * Remove os contatos selecionados |
---|
| 237 | * |
---|
| 238 | * @return |
---|
| 239 | * @param $contacts Object |
---|
| 240 | * @param $show_checkbox Object[optional] |
---|
| 241 | */ |
---|
| 242 | |
---|
| 243 | function delete_contacts($params) { |
---|
| 244 | $this->bo->set_catalog($params['catalog']); |
---|
[3654] | 245 | |
---|
| 246 | if (!is_array($params['contacts']) ){ |
---|
[3657] | 247 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("please select one contact")); |
---|
[3654] | 248 | }else{ |
---|
| 249 | |
---|
| 250 | $status = $this->bo->remove_multiple_entries($params['contacts']); |
---|
| 251 | |
---|
| 252 | $type = $this->page_info['actual_catalog']!=='bo_group_manager'?"contacts":"groups"; |
---|
| 253 | |
---|
| 254 | if($status['success']) |
---|
| 255 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&success_message=".lang("selected $type were removed successfully")); |
---|
| 256 | else |
---|
| 257 | header("Location: index.php?menuaction=mobile.ui_mobilecc.index&error_message=".lang("one or more $type couldnt be removed")); |
---|
| 258 | } |
---|
[3595] | 259 | } |
---|
| 260 | |
---|
| 261 | static function print_contacts($contacts,$show_checkbox=false,$request_from = null) { |
---|
[3573] | 262 | $functions = CreateObject('mobile.common_functions'); |
---|
| 263 | $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); |
---|
| 264 | $p->set_file( |
---|
| 265 | Array( |
---|
| 266 | 'cc_t' => 'contacts_list.tpl' |
---|
| 267 | ) |
---|
| 268 | ); |
---|
| 269 | $p->set_block('cc_t', 'rows_contacts'); |
---|
| 270 | $p->set_block('cc_t', 'row_contacts'); |
---|
[3595] | 271 | $p->set_block('cc_t', 'row_groups'); |
---|
[3573] | 272 | $p->set_block('cc_t', 'no_contacts'); |
---|
[3595] | 273 | |
---|
[3706] | 274 | $bg = "bg-azul"; |
---|
[3573] | 275 | if(!empty($contacts)) { |
---|
| 276 | foreach($contacts as $id => $contact) { |
---|
[3630] | 277 | |
---|
[3595] | 278 | $p->set_var('show_check',$show_checkbox?"inline":"none"); |
---|
[3706] | 279 | $p->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul"); |
---|
| 280 | if($show_checkbox) |
---|
| 281 | $p->set_var("details","email-corpo"); |
---|
| 282 | else |
---|
| 283 | $p->set_var("details","limpar_div margin-geral"); |
---|
[3630] | 284 | if($contact["catalog"]!=="bo_group_manager") { //Contatos |
---|
| 285 | $id=strpos($contact["catalog"],"ldap")===false?$contact["id_contact"]:$id; |
---|
[3629] | 286 | |
---|
| 287 | $mail = ' '; $tel = ' '; |
---|
| 288 | foreach($contact['connections'] as $key => $conn) { |
---|
| 289 | |
---|
| 290 | $test = false; |
---|
| 291 | if ($conn['connection_is_default']) { |
---|
| 292 | $test = true; |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | if (is_array($conn)){ |
---|
| 296 | $test = true; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | if ( $test) { |
---|
| 300 | if ( ($conn['id_type'] == 1) ) |
---|
| 301 | $mail = $conn['connection_value']; |
---|
| 302 | else if ( ($conn['id_type'] == 2) ) |
---|
| 303 | $tel = $conn['connection_value']; |
---|
| 304 | } |
---|
| 305 | } |
---|
| 306 | |
---|
[3573] | 307 | |
---|
[3629] | 308 | $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"]; |
---|
| 309 | $vtel = ($tel==null || $tel==' ')?"none":"inline"; |
---|
| 310 | |
---|
| 311 | if(($mail==' ' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre. |
---|
[3595] | 312 | continue; |
---|
| 313 | |
---|
[3630] | 314 | $p->set_var('show_tel',$vtel); |
---|
| 315 | $p->set_var('email',$mail); |
---|
| 316 | $p->set_var('tel',$tel); |
---|
| 317 | $p->set_var('contact_id',$id); |
---|
| 318 | $p->set_var('lang_tel',lang("tel")); |
---|
| 319 | $p->set_var('contact_name',$functions->strach_string($cn,17)); |
---|
| 320 | |
---|
| 321 | $block = "row_contacts"; |
---|
| 322 | } |
---|
| 323 | else { //Grupos |
---|
| 324 | $id=$contact["id_group"]; |
---|
| 325 | $mail = $cn = $contact["title"]; |
---|
| 326 | $p->set_var('group_id',$contact["id_group"]); |
---|
| 327 | $p->set_var('group_name',$contact["title"]); |
---|
| 328 | $block = "row_groups"; |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | if($request_from==null) { |
---|
[3706] | 332 | $p->set_var('lang_see_details',lang("details")); |
---|
[3630] | 333 | $cat_encode = urlencode($contact["catalog"]); |
---|
| 334 | $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"])); |
---|
| 335 | } |
---|
| 336 | else { |
---|
[3700] | 337 | $p->set_var('lang_see_details',lang("select")); |
---|
[3630] | 338 | $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn"); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | $p->fp('rows',$block,True); |
---|
[3629] | 342 | |
---|
[3573] | 343 | } |
---|
[3595] | 344 | |
---|
[3573] | 345 | } |
---|
| 346 | else { |
---|
| 347 | $p->set_var("lang_no_results",lang("no results found")); |
---|
| 348 | $p->parse("rows","no_contacts"); |
---|
| 349 | } |
---|
| 350 | return $p->fp('out','rows_contacts'); |
---|
| 351 | } |
---|
[3630] | 352 | |
---|
| 353 | /** |
---|
| 354 | * Show details from contact selected |
---|
| 355 | * |
---|
| 356 | * @param $id int |
---|
| 357 | * @param $catalog String |
---|
| 358 | * @return $contact |
---|
| 359 | */ |
---|
[3634] | 360 | function contact_view($params) { |
---|
[3630] | 361 | |
---|
| 362 | if ( empty($params['id']) || empty($params['catalog']) ){ |
---|
| 363 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
| 364 | } |
---|
| 365 | |
---|
| 366 | $this->template->set_file( |
---|
| 367 | Array( |
---|
| 368 | 'cc_v' => 'contact_view.tpl' |
---|
| 369 | ) |
---|
| 370 | ); |
---|
| 371 | |
---|
[3634] | 372 | if ( isset($params['success'])){ |
---|
| 373 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg(lang('contact save successfully')); |
---|
| 374 | } |
---|
| 375 | |
---|
[3630] | 376 | $this->template->set_block('cc_v','body'); |
---|
| 377 | $this->template->set_block('cc_v','people'); |
---|
| 378 | $this->template->set_block('cc_v','people_ldap'); |
---|
| 379 | $this->template->set_block('cc_v','group'); |
---|
| 380 | $this->template->set_block('cc_v','group_row'); |
---|
| 381 | $this->template->set_block('cc_v','buttom'); |
---|
[3634] | 382 | $this->template->set_block('cc_v','buttom_use_contact'); |
---|
[3650] | 383 | $this->template->set_block('cc_v','row_view_operacao'); |
---|
[3630] | 384 | |
---|
[3700] | 385 | $this->template->set_var('title_view_contact',lang("title view contact")); |
---|
[3646] | 386 | $email_to = ""; |
---|
| 387 | |
---|
[3630] | 388 | switch ($params['catalog']){ |
---|
| 389 | |
---|
| 390 | case 'bo_shared_people_manager'; |
---|
| 391 | case 'bo_people_catalog': |
---|
| 392 | |
---|
[3700] | 393 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
[3630] | 394 | $this->bo->set_catalog($params['catalog']); |
---|
| 395 | |
---|
| 396 | $result = $this->bo->bo->get_single_entry($params['id'], array("given_names"=>true,"names_ordered"=>true,"alias"=>true,"family_names"=>true,"companies"=>true,"relations"=>true,"connections"=>true)); |
---|
| 397 | |
---|
| 398 | asort($result['connections']); |
---|
| 399 | |
---|
[3811] | 400 | $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$params['id']); |
---|
[3630] | 401 | $this->template->set_var('id',$params['id']); |
---|
| 402 | $this->template->set_var('catalog',$params['catalog']); |
---|
| 403 | |
---|
| 404 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
| 405 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
| 406 | $this->template->set_var('lang_alias',$result['alias']); |
---|
| 407 | |
---|
| 408 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 409 | $this->template->set_var('lang_name',$result['given_names']); |
---|
| 410 | |
---|
| 411 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 412 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
| 413 | |
---|
| 414 | $var_phone = ""; |
---|
| 415 | $var_email = ""; |
---|
| 416 | foreach($result['connections'] as $conn): |
---|
| 417 | if ( $conn['id_type'] == 1 ){ |
---|
| 418 | if ( !empty($var_email) ) |
---|
| 419 | $var_email .= ' | '; |
---|
| 420 | $var_email .= $conn['connection_value']; |
---|
| 421 | |
---|
| 422 | if ( empty($email_to) ) |
---|
| 423 | $email_to = $var_email; |
---|
| 424 | |
---|
| 425 | }else if ($conn['id_type'] == 2){ |
---|
| 426 | if ( !empty($var_phone)) |
---|
| 427 | $var_phone .= ' | '; |
---|
| 428 | $var_phone .= $conn['connection_value']; |
---|
| 429 | } |
---|
| 430 | endforeach; |
---|
| 431 | |
---|
| 432 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 433 | $this->template->set_var('lang_email',$var_email); |
---|
| 434 | |
---|
| 435 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 436 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 437 | |
---|
| 438 | $this->template->set_var('lang_edit',lang("edit")); |
---|
| 439 | |
---|
| 440 | $this->template->parse("row_body","people"); |
---|
| 441 | |
---|
| 442 | if ($params['catalog'] == 'bo_people_catalog') |
---|
| 443 | $this->template->parse("buttom_editar","buttom"); |
---|
| 444 | |
---|
| 445 | break; |
---|
| 446 | |
---|
| 447 | case 'bo_group_manager': |
---|
[3700] | 448 | $this->template->set_var('lang_contact_title',lang("context group")); |
---|
[3630] | 449 | $this->bo->set_catalog($params['catalog']); |
---|
| 450 | $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true)); |
---|
| 451 | $data = $this->bo->bo->get_contacts_by_group($params['id']); |
---|
[3700] | 452 | |
---|
[3646] | 453 | $email_to = '<'.$result['short_name'].'>'; |
---|
| 454 | |
---|
[3700] | 455 | $this->template->set_var('title_view_contact', $result['title']); |
---|
[3646] | 456 | $this->template->set_var('email_to', $email_to); |
---|
[3630] | 457 | |
---|
| 458 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 459 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 460 | |
---|
| 461 | foreach($data as $dados){ |
---|
| 462 | $this->template->set_var('lang_name', $dados['names_ordered']); |
---|
| 463 | $this->template->set_var('lang_email', $dados['connection_value']); |
---|
[3700] | 464 | $this->template->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul"); |
---|
[3630] | 465 | |
---|
[3700] | 466 | $this->template->set_var('href_details',"ui_mobilecc.contact_view&id=".$dados['id_contact']."&catalog=bo_people_catalog"); |
---|
| 467 | |
---|
[3630] | 468 | $this->template->fp('group_rows','group_row',True); |
---|
| 469 | } |
---|
[3646] | 470 | |
---|
| 471 | $this->template->set_var('email_to', $email_to); |
---|
| 472 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
[3630] | 473 | |
---|
| 474 | $this->template->parse("row_body","group"); |
---|
| 475 | break; |
---|
| 476 | |
---|
| 477 | default: |
---|
| 478 | |
---|
| 479 | if(strpos($params['catalog'],'bo_global_ldap_catalog')==false){ |
---|
| 480 | |
---|
| 481 | $this->bo->set_catalog($params['catalog']); |
---|
| 482 | |
---|
| 483 | $fields = $this->bo->bo->get_fields(true); |
---|
| 484 | $result = $this->bo->bo->get_single_entry($params['id'], $fields); |
---|
| 485 | |
---|
| 486 | $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id); |
---|
| 487 | |
---|
| 488 | $this->template->set_var('cc_name',$result['names_ordered'][0]); |
---|
| 489 | |
---|
| 490 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 491 | $this->template->set_var('lang_name',$result['given_names'][0]); |
---|
| 492 | |
---|
| 493 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 494 | $this->template->set_var('lang_lastname',$result['family_names'][0]); |
---|
| 495 | |
---|
| 496 | $var_phone = ""; |
---|
| 497 | $var_email = ""; |
---|
| 498 | foreach($result['connections'] as $conn): |
---|
| 499 | if ( $conn['id_type'] == 1 ){ |
---|
| 500 | if ( !empty($var_email) ) |
---|
| 501 | $var_email .= ' | '; |
---|
| 502 | $var_email .= $conn['connection_value']; |
---|
| 503 | |
---|
| 504 | if ( empty($email_to) ) |
---|
| 505 | $email_to = $var_email; |
---|
| 506 | |
---|
| 507 | }else if ($conn['id_type'] == 2){ |
---|
| 508 | if ( !empty($var_phone)) |
---|
| 509 | $var_phone .= ' | '; |
---|
| 510 | $var_phone .= $conn['connection_value']; |
---|
| 511 | } |
---|
| 512 | endforeach; |
---|
| 513 | |
---|
| 514 | $this->template->set_var('email_to', $email_to); |
---|
| 515 | |
---|
| 516 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 517 | $this->template->set_var('lang_email',$var_email); |
---|
| 518 | |
---|
| 519 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 520 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 521 | |
---|
| 522 | $this->template->parse("row_body","people_ldap"); |
---|
| 523 | |
---|
| 524 | }else{ |
---|
| 525 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | break; |
---|
| 529 | } |
---|
| 530 | |
---|
[3646] | 531 | if ( !empty($email_to)){ |
---|
| 532 | $this->template->set_var('email_to', $email_to); |
---|
| 533 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
[3650] | 534 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
| 535 | }else if ($params['catalog'] == 'bo_people_catalog'){ |
---|
| 536 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
[3646] | 537 | } |
---|
| 538 | |
---|
[3630] | 539 | $this->template->set_var('lang_back',lang("back")); |
---|
| 540 | $this->template->set_var('lang_use_contact',lang("use contact")); |
---|
| 541 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
| 542 | |
---|
| 543 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | /** |
---|
| 547 | * View Add/Edit contact |
---|
| 548 | * |
---|
| 549 | * @param $id int |
---|
| 550 | * @param $catalog String |
---|
| 551 | * @return $contact |
---|
| 552 | */ |
---|
| 553 | function contact_add_edit($params) { |
---|
| 554 | |
---|
| 555 | $this->template->set_file( |
---|
| 556 | Array( |
---|
| 557 | 'cc_e' => 'contact_add_edit.tpl' |
---|
| 558 | ) |
---|
| 559 | ); |
---|
| 560 | |
---|
| 561 | $this->template->set_block('cc_e','body'); |
---|
| 562 | |
---|
[3634] | 563 | $view = false; |
---|
| 564 | if ( isset($params['erro'])){ |
---|
| 565 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']); |
---|
| 566 | |
---|
| 567 | $result['alias'] = $params['alias']; |
---|
| 568 | $result['given_names'] = $params['given_names']; |
---|
| 569 | $result['family_names'] = $params['family_names']; |
---|
| 570 | $result['names_ordered'] = $params['names_ordered']; |
---|
| 571 | $var_phone = $params['phone']; |
---|
| 572 | $var_email = $params['email']; |
---|
| 573 | $var_connection_email = $params['id_connection_email']; |
---|
| 574 | $var_connection_phone = $params['id_connection_phone']; |
---|
| 575 | $view = true; |
---|
| 576 | |
---|
| 577 | } |
---|
| 578 | |
---|
[3630] | 579 | if ( empty($params['id']) ){ |
---|
| 580 | $title_contact = "title add contact"; |
---|
| 581 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add"; |
---|
| 582 | $confirm = lang("confirm add"); |
---|
| 583 | $params['catalog'] = 'bo_people_catalog'; |
---|
| 584 | }else{ |
---|
| 585 | $title_contact = "title edit contact"; |
---|
| 586 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit"; |
---|
| 587 | $confirm = lang("confirm edit"); |
---|
| 588 | |
---|
[3634] | 589 | $view = true; |
---|
[3630] | 590 | |
---|
[3634] | 591 | if ( !isset($params['erro'])){ |
---|
| 592 | $this->bo->set_catalog($params['catalog']); |
---|
| 593 | $result = $this->bo->bo->get_single_entry($params['id'], array("given_names"=>true,"names_ordered"=>true,"alias"=>true,"family_names"=>true,"companies"=>true,"relations"=>true,"connections"=>true)); |
---|
| 594 | |
---|
| 595 | $var_phone = ""; |
---|
| 596 | $var_email = ""; |
---|
| 597 | foreach($result['connections'] as $conn): |
---|
| 598 | if ( $conn['id_type'] == 1 ){ |
---|
| 599 | if ( (empty($var_email)) && ($conn['connection_is_default']) ){ |
---|
| 600 | $var_email = $conn['connection_value']; |
---|
| 601 | $var_connection_email = $conn['id_connection']; |
---|
| 602 | } |
---|
| 603 | }else if ($conn['id_type'] == 2){ |
---|
| 604 | if ( (empty($var_phone)) && ($conn['connection_is_default'])){ |
---|
| 605 | $var_phone = $conn['connection_value']; |
---|
| 606 | $var_connection_phone = $conn['id_connection']; |
---|
| 607 | } |
---|
[3630] | 608 | } |
---|
[3634] | 609 | endforeach; |
---|
| 610 | } |
---|
[3630] | 611 | |
---|
| 612 | |
---|
| 613 | } |
---|
| 614 | |
---|
[3634] | 615 | if ($view){ |
---|
| 616 | $this->template->set_var('lang_alias',$result['alias']); |
---|
| 617 | $this->template->set_var('lang_name',$result['given_names']); |
---|
| 618 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
| 619 | |
---|
| 620 | $this->template->set_var('var_connection_email', $var_connection_email); |
---|
| 621 | $this->template->set_var('lang_email',$var_email); |
---|
| 622 | |
---|
| 623 | $this->template->set_var('var_connection_phone', $var_connection_phone); |
---|
| 624 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 625 | |
---|
| 626 | } |
---|
| 627 | |
---|
[3630] | 628 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
| 629 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
| 630 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 631 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 632 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 633 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 634 | |
---|
| 635 | $this->template->set_var('catalog', $params['catalog']); |
---|
| 636 | |
---|
| 637 | $this->template->set_var('lang_title_add_edit',lang($title_contact)); |
---|
| 638 | $this->template->set_var('form_action', $form_action); |
---|
| 639 | |
---|
| 640 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
| 641 | $this->template->set_var('lang_back',lang("back")); |
---|
| 642 | $this->template->set_var('lang_cancel',lang("cancel")); |
---|
| 643 | $this->template->set_var('lang_confirm', $confirm); |
---|
| 644 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
| 645 | $this->template->set_var('id',$params['id']); |
---|
| 646 | |
---|
| 647 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
| 648 | } |
---|
[3573] | 649 | |
---|
[3630] | 650 | /** |
---|
| 651 | * Add contact |
---|
| 652 | * |
---|
| 653 | * @param $id int |
---|
| 654 | * @param $catalog String |
---|
| 655 | * @return $contact |
---|
| 656 | */ |
---|
| 657 | function contact_add($params) { |
---|
| 658 | |
---|
| 659 | $data['alias'] = $params['alias']; |
---|
| 660 | $data['given_names'] = $params['given_names']; |
---|
| 661 | $data['family_names'] = $params['family_names']; |
---|
| 662 | $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names']; |
---|
| 663 | $data['is_quick_add'] = true; |
---|
| 664 | |
---|
[3634] | 665 | $answer = $this->verifyData($params); |
---|
[3630] | 666 | |
---|
[3634] | 667 | if (!empty($answer)){ |
---|
| 668 | $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names']; |
---|
| 669 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
| 670 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
| 671 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
[3630] | 672 | } |
---|
[3634] | 673 | else |
---|
| 674 | { |
---|
| 675 | $this->bo->set_catalog($params['catalog']); |
---|
| 676 | |
---|
| 677 | if ( !empty($params['email']) ){ |
---|
| 678 | $data['connections']['default_email']['connection_value'] = $params['email']; |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | if ( !empty($params['phone']) ){ |
---|
| 682 | $data['connections']['default_phone']['connection_value'] = $params['phone']; |
---|
| 683 | } |
---|
| 684 | |
---|
| 685 | $this->bo->set_catalog($params['catalog']); |
---|
| 686 | $contact_id = $this->bo->bo->quick_add($data); |
---|
| 687 | |
---|
| 688 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1'); |
---|
| 689 | } |
---|
| 690 | } |
---|
[3630] | 691 | |
---|
| 692 | /** |
---|
| 693 | * Edit contact |
---|
| 694 | * |
---|
| 695 | * @param $id int |
---|
| 696 | * @param $catalog String |
---|
| 697 | * @return $contact |
---|
| 698 | */ |
---|
| 699 | function contact_edit($params) { |
---|
| 700 | |
---|
| 701 | $data['alias'] = $params['alias']; |
---|
| 702 | $data['given_names'] = $params['given_names']; |
---|
| 703 | $data['family_names'] = $params['family_names']; |
---|
| 704 | $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names']; |
---|
| 705 | |
---|
| 706 | $cont = 0; |
---|
| 707 | |
---|
[3634] | 708 | $answer = $this->verifyData($params); |
---|
[3630] | 709 | |
---|
[3634] | 710 | if (!empty($answer)){ |
---|
| 711 | $retorno = '&catalog=' . $params['catalog'] . '&id='. $params['id'] .'&alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names']; |
---|
| 712 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
| 713 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
| 714 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
[3630] | 715 | } |
---|
[3634] | 716 | else |
---|
| 717 | { |
---|
[3630] | 718 | |
---|
[3634] | 719 | $this->bo->set_catalog($params['catalog']); |
---|
| 720 | $types = $this->bo->bo->get_all_connections_types(); |
---|
| 721 | |
---|
| 722 | if ( !empty($params['email']) || !empty($params['id_connection_email']) ){ |
---|
| 723 | $cont++; |
---|
| 724 | |
---|
| 725 | if (empty($params['id_connection_email'])){ |
---|
| 726 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
| 727 | $data['connections']['connection' . $cont]['connection_name'] = $types[1]; |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email']; |
---|
| 731 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 1; |
---|
| 732 | $data['connections']['connection' . $cont]['connection_value'] = $params['email']; |
---|
| 733 | |
---|
[3630] | 734 | } |
---|
[3634] | 735 | |
---|
| 736 | if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){ |
---|
| 737 | $cont++; |
---|
| 738 | |
---|
| 739 | if (empty($params['id_connection_phone'])){ |
---|
| 740 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
| 741 | $data['connections']['connection' . $cont]['connection_name'] = $types[2]; |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone']; |
---|
| 745 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 2; |
---|
| 746 | $data['connections']['connection' . $cont]['connection_value'] = $params['phone']; |
---|
| 747 | |
---|
| 748 | } |
---|
| 749 | |
---|
| 750 | $contact_id = $this->bo->bo->update_single_info($params['id'], $data); |
---|
[3630] | 751 | |
---|
[3634] | 752 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1'); |
---|
| 753 | |
---|
[3630] | 754 | } |
---|
| 755 | |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | /** |
---|
[3634] | 759 | * Validate data when register contact |
---|
| 760 | * Validate E-mail, Phone and Name(NotEmpty) |
---|
[3630] | 761 | * |
---|
[3634] | 762 | * @param $data Array |
---|
[3630] | 763 | * @return Boolean |
---|
| 764 | */ |
---|
[3634] | 765 | static function verifyData($data){ |
---|
| 766 | |
---|
| 767 | $valid = ''; |
---|
| 768 | $field = false; |
---|
| 769 | |
---|
| 770 | // Verify if phone is valid |
---|
| 771 | if ( !empty($data['phone']) && empty($valid) ){ |
---|
[3630] | 772 | |
---|
[3634] | 773 | $field = true; |
---|
| 774 | |
---|
| 775 | $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#"; |
---|
| 776 | |
---|
| 777 | if (!preg_match($pattern, $data['phone'])){ |
---|
| 778 | $valid = lang('invalid field phone'); |
---|
| 779 | } |
---|
| 780 | |
---|
[3630] | 781 | } |
---|
[3634] | 782 | |
---|
| 783 | // Verify if e-mail is valid |
---|
| 784 | if ( !empty($data['email']) ){ |
---|
| 785 | |
---|
| 786 | $field = true; |
---|
| 787 | |
---|
| 788 | $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$"; |
---|
| 789 | |
---|
| 790 | if (!eregi($pattern, $data['email'])){ |
---|
| 791 | $valid = lang('invalid field e-mail'); |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | // Verify if exist e-mail or phone |
---|
| 797 | if (!$field) |
---|
| 798 | $valid = lang('Tel or email is required'); |
---|
[3630] | 799 | |
---|
[3634] | 800 | // Verify if name is empty |
---|
| 801 | if ( empty($data['given_names']) ) |
---|
| 802 | $valid = lang('Name is mandatory'); |
---|
[3630] | 803 | |
---|
[3634] | 804 | return $valid; |
---|
| 805 | |
---|
[3630] | 806 | } |
---|
| 807 | |
---|
| 808 | |
---|
[480] | 809 | } |
---|
[3573] | 810 | |
---|
| 811 | |
---|
[480] | 812 | ?> |
---|