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