[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; |
---|
[3822] | 291 | if ($conn['connection_is_default']) { |
---|
[3629] | 292 | $test = true; |
---|
[3822] | 293 | } |
---|
[3629] | 294 | |
---|
| 295 | if (is_array($conn)){ |
---|
| 296 | $test = true; |
---|
[3822] | 297 | }else{ |
---|
| 298 | $test = false; |
---|
| 299 | } |
---|
[3629] | 300 | if ( $test) { |
---|
[3822] | 301 | if ( ($conn['id_type'] == 1) ) |
---|
[3629] | 302 | $mail = $conn['connection_value']; |
---|
[3822] | 303 | else if ( ($conn['id_type'] == 2) ) |
---|
[3629] | 304 | $tel = $conn['connection_value']; |
---|
[3822] | 305 | |
---|
[3824] | 306 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){ |
---|
[3822] | 307 | if ( ($conn['type'] == 'email') ) |
---|
| 308 | $mail = $conn['connection_value']; |
---|
| 309 | else if ( ($conn['type'] == 'phone') ) |
---|
| 310 | $tel = $conn['connection_value']; |
---|
| 311 | |
---|
| 312 | } |
---|
| 313 | } |
---|
[3629] | 314 | } |
---|
[3822] | 315 | |
---|
[3629] | 316 | |
---|
[3573] | 317 | |
---|
[3629] | 318 | $cn = is_array($contact["names_ordered"])?$contact["names_ordered"][0]:$contact["names_ordered"]; |
---|
| 319 | $vtel = ($tel==null || $tel==' ')?"none":"inline"; |
---|
| 320 | |
---|
| 321 | if(($mail==' ' || $mail==null) && isset($request_from))//Se vier de outro módulo e não possuir e-mail, não mostre. |
---|
[3595] | 322 | continue; |
---|
| 323 | |
---|
[3630] | 324 | $p->set_var('show_tel',$vtel); |
---|
| 325 | $p->set_var('email',$mail); |
---|
| 326 | $p->set_var('tel',$tel); |
---|
| 327 | $p->set_var('contact_id',$id); |
---|
| 328 | $p->set_var('lang_tel',lang("tel")); |
---|
| 329 | $p->set_var('contact_name',$functions->strach_string($cn,17)); |
---|
| 330 | |
---|
| 331 | $block = "row_contacts"; |
---|
| 332 | } |
---|
| 333 | else { //Grupos |
---|
| 334 | $id=$contact["id_group"]; |
---|
| 335 | $mail = $cn = $contact["title"]; |
---|
| 336 | $p->set_var('group_id',$contact["id_group"]); |
---|
| 337 | $p->set_var('group_name',$contact["title"]); |
---|
| 338 | $block = "row_groups"; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | if($request_from==null) { |
---|
[3706] | 342 | $p->set_var('lang_see_details',lang("details")); |
---|
[3630] | 343 | $cat_encode = urlencode($contact["catalog"]); |
---|
| 344 | $p->set_var('href_details',"ui_mobilecc.contact_view&id=$id&catalog=".urlencode($contact["catalog"])); |
---|
| 345 | } |
---|
| 346 | else { |
---|
[3700] | 347 | $p->set_var('lang_see_details',lang("select")); |
---|
[3630] | 348 | $p->set_var("href_details","ui_mobilemail.add_recipient&mail=$mail&cn=$cn"); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | $p->fp('rows',$block,True); |
---|
[3629] | 352 | |
---|
[3573] | 353 | } |
---|
[3595] | 354 | |
---|
[3573] | 355 | } |
---|
| 356 | else { |
---|
| 357 | $p->set_var("lang_no_results",lang("no results found")); |
---|
| 358 | $p->parse("rows","no_contacts"); |
---|
| 359 | } |
---|
| 360 | return $p->fp('out','rows_contacts'); |
---|
| 361 | } |
---|
[3630] | 362 | |
---|
| 363 | /** |
---|
| 364 | * Show details from contact selected |
---|
| 365 | * |
---|
| 366 | * @param $id int |
---|
| 367 | * @param $catalog String |
---|
| 368 | * @return $contact |
---|
| 369 | */ |
---|
[3634] | 370 | function contact_view($params) { |
---|
[3630] | 371 | |
---|
| 372 | if ( empty($params['id']) || empty($params['catalog']) ){ |
---|
| 373 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | $this->template->set_file( |
---|
| 377 | Array( |
---|
| 378 | 'cc_v' => 'contact_view.tpl' |
---|
| 379 | ) |
---|
| 380 | ); |
---|
| 381 | |
---|
[3634] | 382 | if ( isset($params['success'])){ |
---|
| 383 | $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg(lang('contact save successfully')); |
---|
| 384 | } |
---|
| 385 | |
---|
[3630] | 386 | $this->template->set_block('cc_v','body'); |
---|
| 387 | $this->template->set_block('cc_v','people'); |
---|
| 388 | $this->template->set_block('cc_v','people_ldap'); |
---|
| 389 | $this->template->set_block('cc_v','group'); |
---|
| 390 | $this->template->set_block('cc_v','group_row'); |
---|
| 391 | $this->template->set_block('cc_v','buttom'); |
---|
[3634] | 392 | $this->template->set_block('cc_v','buttom_use_contact'); |
---|
[3650] | 393 | $this->template->set_block('cc_v','row_view_operacao'); |
---|
[3630] | 394 | |
---|
[3700] | 395 | $this->template->set_var('title_view_contact',lang("title view contact")); |
---|
[3646] | 396 | $email_to = ""; |
---|
| 397 | |
---|
[3630] | 398 | switch ($params['catalog']){ |
---|
| 399 | |
---|
| 400 | case 'bo_shared_people_manager'; |
---|
| 401 | case 'bo_people_catalog': |
---|
| 402 | |
---|
[3700] | 403 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
[3630] | 404 | $this->bo->set_catalog($params['catalog']); |
---|
| 405 | |
---|
| 406 | $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)); |
---|
| 407 | |
---|
| 408 | asort($result['connections']); |
---|
| 409 | |
---|
[3811] | 410 | $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$params['id']); |
---|
[3630] | 411 | $this->template->set_var('id',$params['id']); |
---|
| 412 | $this->template->set_var('catalog',$params['catalog']); |
---|
| 413 | |
---|
| 414 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
| 415 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
| 416 | $this->template->set_var('lang_alias',$result['alias']); |
---|
| 417 | |
---|
| 418 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 419 | $this->template->set_var('lang_name',$result['given_names']); |
---|
| 420 | |
---|
| 421 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 422 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
| 423 | |
---|
| 424 | $var_phone = ""; |
---|
| 425 | $var_email = ""; |
---|
| 426 | foreach($result['connections'] as $conn): |
---|
| 427 | if ( $conn['id_type'] == 1 ){ |
---|
| 428 | if ( !empty($var_email) ) |
---|
| 429 | $var_email .= ' | '; |
---|
| 430 | $var_email .= $conn['connection_value']; |
---|
| 431 | |
---|
| 432 | if ( empty($email_to) ) |
---|
| 433 | $email_to = $var_email; |
---|
| 434 | |
---|
| 435 | }else if ($conn['id_type'] == 2){ |
---|
| 436 | if ( !empty($var_phone)) |
---|
| 437 | $var_phone .= ' | '; |
---|
| 438 | $var_phone .= $conn['connection_value']; |
---|
| 439 | } |
---|
[3823] | 440 | |
---|
[3825] | 441 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){ |
---|
[3823] | 442 | if ( $conn['type'] == 'email' ){ |
---|
| 443 | if ( !empty($var_email) ) |
---|
| 444 | $var_email .= ' | '; |
---|
| 445 | $var_email .= $conn['connection_value']; |
---|
| 446 | |
---|
| 447 | if ( empty($email_to) ) |
---|
| 448 | $email_to = $var_email; |
---|
| 449 | |
---|
| 450 | }else if ($conn['type'] == 'phone'){ |
---|
| 451 | if ( !empty($var_phone)) |
---|
| 452 | $var_phone .= ' | '; |
---|
| 453 | $var_phone .= $conn['connection_value']; |
---|
| 454 | } |
---|
| 455 | } |
---|
[3630] | 456 | endforeach; |
---|
| 457 | |
---|
| 458 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 459 | $this->template->set_var('lang_email',$var_email); |
---|
| 460 | |
---|
| 461 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 462 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 463 | |
---|
| 464 | $this->template->set_var('lang_edit',lang("edit")); |
---|
| 465 | |
---|
| 466 | $this->template->parse("row_body","people"); |
---|
| 467 | |
---|
| 468 | if ($params['catalog'] == 'bo_people_catalog') |
---|
| 469 | $this->template->parse("buttom_editar","buttom"); |
---|
| 470 | |
---|
| 471 | break; |
---|
| 472 | |
---|
| 473 | case 'bo_group_manager': |
---|
[3700] | 474 | $this->template->set_var('lang_contact_title',lang("context group")); |
---|
[3630] | 475 | $this->bo->set_catalog($params['catalog']); |
---|
| 476 | $result = $this->bo->bo->get_single_entry($params['id'], array("id_group"=>true,"title"=>true,"short_name"=>true)); |
---|
| 477 | $data = $this->bo->bo->get_contacts_by_group($params['id']); |
---|
[3700] | 478 | |
---|
[3646] | 479 | $email_to = '<'.$result['short_name'].'>'; |
---|
| 480 | |
---|
[3700] | 481 | $this->template->set_var('title_view_contact', $result['title']); |
---|
[3646] | 482 | $this->template->set_var('email_to', $email_to); |
---|
[3630] | 483 | |
---|
| 484 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 485 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 486 | |
---|
| 487 | foreach($data as $dados){ |
---|
| 488 | $this->template->set_var('lang_name', $dados['names_ordered']); |
---|
| 489 | $this->template->set_var('lang_email', $dados['connection_value']); |
---|
[3700] | 490 | $this->template->set_var('bg',$bg=="bg-azul"?$bg="bg-branco":$bg="bg-azul"); |
---|
[3630] | 491 | |
---|
[3700] | 492 | $this->template->set_var('href_details',"ui_mobilecc.contact_view&id=".$dados['id_contact']."&catalog=bo_people_catalog"); |
---|
| 493 | |
---|
[3630] | 494 | $this->template->fp('group_rows','group_row',True); |
---|
| 495 | } |
---|
[3646] | 496 | |
---|
| 497 | $this->template->set_var('email_to', $email_to); |
---|
| 498 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
[3630] | 499 | |
---|
| 500 | $this->template->parse("row_body","group"); |
---|
| 501 | break; |
---|
| 502 | |
---|
| 503 | default: |
---|
| 504 | |
---|
| 505 | if(strpos($params['catalog'],'bo_global_ldap_catalog')==false){ |
---|
| 506 | |
---|
| 507 | $this->bo->set_catalog($params['catalog']); |
---|
| 508 | |
---|
| 509 | $fields = $this->bo->bo->get_fields(true); |
---|
| 510 | $result = $this->bo->bo->get_single_entry($params['id'], $fields); |
---|
| 511 | |
---|
| 512 | $this->template->set_var('photo', '../index.php?menuaction=contactcenter.ui_data.data_manager&method=get_photo&id='.$id); |
---|
| 513 | |
---|
| 514 | $this->template->set_var('cc_name',$result['names_ordered'][0]); |
---|
| 515 | |
---|
| 516 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 517 | $this->template->set_var('lang_name',$result['given_names'][0]); |
---|
| 518 | |
---|
| 519 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 520 | $this->template->set_var('lang_lastname',$result['family_names'][0]); |
---|
| 521 | |
---|
| 522 | $var_phone = ""; |
---|
| 523 | $var_email = ""; |
---|
| 524 | foreach($result['connections'] as $conn): |
---|
| 525 | if ( $conn['id_type'] == 1 ){ |
---|
| 526 | if ( !empty($var_email) ) |
---|
| 527 | $var_email .= ' | '; |
---|
| 528 | $var_email .= $conn['connection_value']; |
---|
| 529 | |
---|
| 530 | if ( empty($email_to) ) |
---|
| 531 | $email_to = $var_email; |
---|
| 532 | |
---|
| 533 | }else if ($conn['id_type'] == 2){ |
---|
| 534 | if ( !empty($var_phone)) |
---|
| 535 | $var_phone .= ' | '; |
---|
| 536 | $var_phone .= $conn['connection_value']; |
---|
| 537 | } |
---|
[3823] | 538 | |
---|
[3825] | 539 | if (($conn['id_type'] == null) || ($conn['id_type'] == '_NONE_')){ |
---|
[3823] | 540 | if ( $conn['type'] == 'email' ){ |
---|
| 541 | if ( !empty($var_email) ) |
---|
| 542 | $var_email .= ' | '; |
---|
| 543 | $var_email .= $conn['connection_value']; |
---|
| 544 | |
---|
| 545 | if ( empty($email_to) ) |
---|
| 546 | $email_to = $var_email; |
---|
| 547 | |
---|
| 548 | }else if ($conn['type'] == 'phone'){ |
---|
| 549 | if ( !empty($var_phone)) |
---|
| 550 | $var_phone .= ' | '; |
---|
| 551 | $var_phone .= $conn['connection_value']; |
---|
| 552 | } |
---|
| 553 | } |
---|
[3630] | 554 | endforeach; |
---|
| 555 | |
---|
| 556 | $this->template->set_var('email_to', $email_to); |
---|
| 557 | |
---|
| 558 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 559 | $this->template->set_var('lang_email',$var_email); |
---|
| 560 | |
---|
| 561 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 562 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 563 | |
---|
| 564 | $this->template->parse("row_body","people_ldap"); |
---|
| 565 | |
---|
| 566 | }else{ |
---|
| 567 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.init_cc'); |
---|
| 568 | } |
---|
| 569 | |
---|
| 570 | break; |
---|
| 571 | } |
---|
| 572 | |
---|
[3646] | 573 | if ( !empty($email_to)){ |
---|
| 574 | $this->template->set_var('email_to', $email_to); |
---|
| 575 | $this->template->parse("buttom_use","buttom_use_contact"); |
---|
[3650] | 576 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
| 577 | }else if ($params['catalog'] == 'bo_people_catalog'){ |
---|
| 578 | $this->template->parse("row_operacao","row_view_operacao"); |
---|
[3646] | 579 | } |
---|
| 580 | |
---|
[3630] | 581 | $this->template->set_var('lang_back',lang("back")); |
---|
| 582 | $this->template->set_var('lang_use_contact',lang("use contact")); |
---|
| 583 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
| 584 | |
---|
| 585 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | /** |
---|
| 589 | * View Add/Edit contact |
---|
| 590 | * |
---|
| 591 | * @param $id int |
---|
| 592 | * @param $catalog String |
---|
| 593 | * @return $contact |
---|
| 594 | */ |
---|
| 595 | function contact_add_edit($params) { |
---|
| 596 | |
---|
| 597 | $this->template->set_file( |
---|
| 598 | Array( |
---|
| 599 | 'cc_e' => 'contact_add_edit.tpl' |
---|
| 600 | ) |
---|
| 601 | ); |
---|
| 602 | |
---|
| 603 | $this->template->set_block('cc_e','body'); |
---|
| 604 | |
---|
[3634] | 605 | $view = false; |
---|
| 606 | if ( isset($params['erro'])){ |
---|
| 607 | $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params['erro']); |
---|
| 608 | |
---|
| 609 | $result['alias'] = $params['alias']; |
---|
| 610 | $result['given_names'] = $params['given_names']; |
---|
| 611 | $result['family_names'] = $params['family_names']; |
---|
| 612 | $result['names_ordered'] = $params['names_ordered']; |
---|
| 613 | $var_phone = $params['phone']; |
---|
| 614 | $var_email = $params['email']; |
---|
| 615 | $var_connection_email = $params['id_connection_email']; |
---|
| 616 | $var_connection_phone = $params['id_connection_phone']; |
---|
| 617 | $view = true; |
---|
| 618 | |
---|
| 619 | } |
---|
| 620 | |
---|
[3630] | 621 | if ( empty($params['id']) ){ |
---|
| 622 | $title_contact = "title add contact"; |
---|
| 623 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_add"; |
---|
| 624 | $confirm = lang("confirm add"); |
---|
| 625 | $params['catalog'] = 'bo_people_catalog'; |
---|
| 626 | }else{ |
---|
| 627 | $title_contact = "title edit contact"; |
---|
| 628 | $form_action = "index.php?menuaction=mobile.ui_mobilecc.contact_edit"; |
---|
| 629 | $confirm = lang("confirm edit"); |
---|
| 630 | |
---|
[3634] | 631 | $view = true; |
---|
[3630] | 632 | |
---|
[3634] | 633 | if ( !isset($params['erro'])){ |
---|
| 634 | $this->bo->set_catalog($params['catalog']); |
---|
| 635 | $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)); |
---|
| 636 | |
---|
| 637 | $var_phone = ""; |
---|
| 638 | $var_email = ""; |
---|
| 639 | foreach($result['connections'] as $conn): |
---|
| 640 | if ( $conn['id_type'] == 1 ){ |
---|
| 641 | if ( (empty($var_email)) && ($conn['connection_is_default']) ){ |
---|
| 642 | $var_email = $conn['connection_value']; |
---|
| 643 | $var_connection_email = $conn['id_connection']; |
---|
| 644 | } |
---|
| 645 | }else if ($conn['id_type'] == 2){ |
---|
| 646 | if ( (empty($var_phone)) && ($conn['connection_is_default'])){ |
---|
| 647 | $var_phone = $conn['connection_value']; |
---|
| 648 | $var_connection_phone = $conn['id_connection']; |
---|
| 649 | } |
---|
[3630] | 650 | } |
---|
[3634] | 651 | endforeach; |
---|
| 652 | } |
---|
[3630] | 653 | |
---|
| 654 | |
---|
| 655 | } |
---|
| 656 | |
---|
[3634] | 657 | if ($view){ |
---|
| 658 | $this->template->set_var('lang_alias',$result['alias']); |
---|
| 659 | $this->template->set_var('lang_name',$result['given_names']); |
---|
| 660 | $this->template->set_var('lang_lastname',$result['family_names']); |
---|
| 661 | |
---|
| 662 | $this->template->set_var('var_connection_email', $var_connection_email); |
---|
| 663 | $this->template->set_var('lang_email',$var_email); |
---|
| 664 | |
---|
| 665 | $this->template->set_var('var_connection_phone', $var_connection_phone); |
---|
| 666 | $this->template->set_var('lang_phone',$var_phone); |
---|
| 667 | |
---|
| 668 | } |
---|
| 669 | |
---|
[3630] | 670 | $this->template->set_var('cc_name',$result['names_ordered']); |
---|
| 671 | $this->template->set_var('lang_title_alias',lang("Alias")); |
---|
| 672 | $this->template->set_var('lang_title_name',lang("Name")); |
---|
| 673 | $this->template->set_var('lang_title_lastname',lang("Family Names")); |
---|
| 674 | $this->template->set_var('lang_title_email',lang("Email")); |
---|
| 675 | $this->template->set_var('lang_title_phone',lang("Phone")); |
---|
| 676 | |
---|
| 677 | $this->template->set_var('catalog', $params['catalog']); |
---|
| 678 | |
---|
| 679 | $this->template->set_var('lang_title_add_edit',lang($title_contact)); |
---|
| 680 | $this->template->set_var('form_action', $form_action); |
---|
| 681 | |
---|
| 682 | $this->template->set_var('lang_contact_title',lang("context contact")); |
---|
| 683 | $this->template->set_var('lang_back',lang("back")); |
---|
| 684 | $this->template->set_var('lang_cancel',lang("cancel")); |
---|
| 685 | $this->template->set_var('lang_confirm', $confirm); |
---|
| 686 | $this->template->set_var('lang_selecteds',lang("selecteds")); |
---|
| 687 | $this->template->set_var('id',$params['id']); |
---|
| 688 | |
---|
| 689 | $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','body')); |
---|
| 690 | } |
---|
[3573] | 691 | |
---|
[3630] | 692 | /** |
---|
| 693 | * Add contact |
---|
| 694 | * |
---|
| 695 | * @param $id int |
---|
| 696 | * @param $catalog String |
---|
| 697 | * @return $contact |
---|
| 698 | */ |
---|
| 699 | function contact_add($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 | $data['is_quick_add'] = true; |
---|
| 706 | |
---|
[3634] | 707 | $answer = $this->verifyData($params); |
---|
[3630] | 708 | |
---|
[3634] | 709 | if (!empty($answer)){ |
---|
| 710 | $retorno = 'alias='.$data['alias'] . '&given_names='.$data['given_names'] . '&family_names='.$data['family_names'] . '&names_ordered='.$data['given_names'] . ' ' . $data['family_names']; |
---|
| 711 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
| 712 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
| 713 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
[3630] | 714 | } |
---|
[3634] | 715 | else |
---|
| 716 | { |
---|
| 717 | $this->bo->set_catalog($params['catalog']); |
---|
| 718 | |
---|
| 719 | if ( !empty($params['email']) ){ |
---|
| 720 | $data['connections']['default_email']['connection_value'] = $params['email']; |
---|
| 721 | } |
---|
| 722 | |
---|
| 723 | if ( !empty($params['phone']) ){ |
---|
| 724 | $data['connections']['default_phone']['connection_value'] = $params['phone']; |
---|
| 725 | } |
---|
| 726 | |
---|
| 727 | $this->bo->set_catalog($params['catalog']); |
---|
| 728 | $contact_id = $this->bo->bo->quick_add($data); |
---|
| 729 | |
---|
| 730 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'] . '&success=1'); |
---|
| 731 | } |
---|
| 732 | } |
---|
[3630] | 733 | |
---|
| 734 | /** |
---|
| 735 | * Edit contact |
---|
| 736 | * |
---|
| 737 | * @param $id int |
---|
| 738 | * @param $catalog String |
---|
| 739 | * @return $contact |
---|
| 740 | */ |
---|
| 741 | function contact_edit($params) { |
---|
| 742 | |
---|
| 743 | $data['alias'] = $params['alias']; |
---|
| 744 | $data['given_names'] = $params['given_names']; |
---|
| 745 | $data['family_names'] = $params['family_names']; |
---|
| 746 | $data['names_ordered'] = $data['given_names'] . ' ' . $data['family_names']; |
---|
| 747 | |
---|
| 748 | $cont = 0; |
---|
| 749 | |
---|
[3634] | 750 | $answer = $this->verifyData($params); |
---|
[3630] | 751 | |
---|
[3634] | 752 | if (!empty($answer)){ |
---|
| 753 | $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']; |
---|
| 754 | $retorno .= '&id_connection_email='.$params['id_connection_email'] . '&id_connection_phone='.$params['id_connection_phone']; |
---|
| 755 | $retorno .= '&email='.$params['email'] . '&phone='.$params['phone']; |
---|
| 756 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_add_edit&erro='.$answer.'&'.$retorno); |
---|
[3630] | 757 | } |
---|
[3634] | 758 | else |
---|
| 759 | { |
---|
[3630] | 760 | |
---|
[3634] | 761 | $this->bo->set_catalog($params['catalog']); |
---|
| 762 | $types = $this->bo->bo->get_all_connections_types(); |
---|
| 763 | |
---|
| 764 | if ( !empty($params['email']) || !empty($params['id_connection_email']) ){ |
---|
| 765 | $cont++; |
---|
| 766 | |
---|
| 767 | if (empty($params['id_connection_email'])){ |
---|
| 768 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
| 769 | $data['connections']['connection' . $cont]['connection_name'] = $types[1]; |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_email']; |
---|
| 773 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 1; |
---|
| 774 | $data['connections']['connection' . $cont]['connection_value'] = $params['email']; |
---|
| 775 | |
---|
[3630] | 776 | } |
---|
[3634] | 777 | |
---|
| 778 | if ( !empty($params['phone']) || !empty($params['id_connection_phone']) ){ |
---|
| 779 | $cont++; |
---|
| 780 | |
---|
| 781 | if (empty($params['id_connection_phone'])){ |
---|
| 782 | $data['connections']['connection' . $cont]['connection_is_default'] = true; |
---|
| 783 | $data['connections']['connection' . $cont]['connection_name'] = $types[2]; |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | $data['connections']['connection' . $cont]['id_connection'] = $params['id_connection_phone']; |
---|
| 787 | $data['connections']['connection' . $cont]['id_typeof_connection'] = 2; |
---|
| 788 | $data['connections']['connection' . $cont]['connection_value'] = $params['phone']; |
---|
| 789 | |
---|
| 790 | } |
---|
| 791 | |
---|
| 792 | $contact_id = $this->bo->bo->update_single_info($params['id'], $data); |
---|
[3630] | 793 | |
---|
[3634] | 794 | header('Location: ../mobile/index.php?menuaction=mobile.ui_mobilecc.contact_view&id='.$contact_id.'&catalog='.$params['catalog'].'&success=1'); |
---|
| 795 | |
---|
[3630] | 796 | } |
---|
| 797 | |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | /** |
---|
[3634] | 801 | * Validate data when register contact |
---|
| 802 | * Validate E-mail, Phone and Name(NotEmpty) |
---|
[3630] | 803 | * |
---|
[3634] | 804 | * @param $data Array |
---|
[3630] | 805 | * @return Boolean |
---|
| 806 | */ |
---|
[3634] | 807 | static function verifyData($data){ |
---|
| 808 | |
---|
| 809 | $valid = ''; |
---|
| 810 | $field = false; |
---|
| 811 | |
---|
| 812 | // Verify if phone is valid |
---|
| 813 | if ( !empty($data['phone']) && empty($valid) ){ |
---|
[3630] | 814 | |
---|
[3634] | 815 | $field = true; |
---|
| 816 | |
---|
| 817 | $pattern = "#^(?:(?:\(?\+?(?P<country>\d{2,4})\)?\s*)?\(?(?P<city>\d{2,3})\)?\s*)?(?P<n1>\d{3,4})[-\s.]?(?P<n2>\d{4})$#"; |
---|
| 818 | |
---|
| 819 | if (!preg_match($pattern, $data['phone'])){ |
---|
| 820 | $valid = lang('invalid field phone'); |
---|
| 821 | } |
---|
| 822 | |
---|
[3630] | 823 | } |
---|
[3634] | 824 | |
---|
| 825 | // Verify if e-mail is valid |
---|
| 826 | if ( !empty($data['email']) ){ |
---|
| 827 | |
---|
| 828 | $field = true; |
---|
| 829 | |
---|
| 830 | $pattern = "^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$"; |
---|
| 831 | |
---|
| 832 | if (!eregi($pattern, $data['email'])){ |
---|
| 833 | $valid = lang('invalid field e-mail'); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | // Verify if exist e-mail or phone |
---|
| 839 | if (!$field) |
---|
| 840 | $valid = lang('Tel or email is required'); |
---|
[3630] | 841 | |
---|
[3634] | 842 | // Verify if name is empty |
---|
| 843 | if ( empty($data['given_names']) ) |
---|
| 844 | $valid = lang('Name is mandatory'); |
---|
[3630] | 845 | |
---|
[3634] | 846 | return $valid; |
---|
| 847 | |
---|
[3630] | 848 | } |
---|
| 849 | |
---|
| 850 | |
---|
[480] | 851 | } |
---|
[3573] | 852 | |
---|
| 853 | |
---|
[480] | 854 | ?> |
---|