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