1<?php 2 /**************************************************************************\ 3 * phpGroupWare Application - phonelog * 4 * http://www.phpgroupware.org * 5 * Written by Mathieu van Loon <mathieu@playcollective.com> * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: editentry.php 21081 2010-03-25 22:55:17Z Caeies $ */ 14 15 if(empty($querytype) || !$querytype) 16 { 17 $querytype = "NEW"; 18 } 19 if(($querytype=="SELECT" || $querytype=="UPDATE") && !$callid) 20 { 21 die("No callid supplied while require for this type of query : $querytype. Session halted."); 22 } 23 if ($querytype=="INSERT" || $querytype=="UPDATE") 24 { 25 $GLOBALS['phpgw_info']["flags"] = array("noheader" => True, "nonavbar" => True); 26 } 27 28 $GLOBALS['phpgw_info']["flags"]["currentapp"] = "phonelog"; 29 include("../header.inc.php"); 30 31 // PREPARE LISTS 32 if(is_array($phonelog["entry_status"])) 33 { 34 for($i=1;$i<=max(array_keys($phonelog["entry_status"]));$i++) 35 { 36 $callstatus_list[] = array($i, $phonelog["entry_status"][$i]); 37 } 38 } 39 40 $calldate_month_list[] = array(1, lang("january")); 41 $calldate_month_list[] = array(2, lang("february")); 42 $calldate_month_list[] = array(3, lang("march")); 43 $calldate_month_list[] = array(4, lang("may")); 44 $calldate_month_list[] = array(5, lang("april")); 45 $calldate_month_list[] = array(6, lang("june")); 46 $calldate_month_list[] = array(7, lang("july")); 47 $calldate_month_list[] = array(8, lang("august")); 48 $calldate_month_list[] = array(9, lang("september")); 49 $calldate_month_list[] = array(10, lang("october")); 50 $calldate_month_list[] = array(11, lang("november")); 51 $calldate_month_list[] = array(12, lang("december")); 52 53 $users = $GLOBALS['phpgw']->accounts->get_list("accounts"); 54 for($i=0;$i<sizeof($users);$i++) 55 { 56 $callfor_list[$i] = array($users[$i]["account_id"], $users[$i]["account_firstname"] . " " . $users[$i]["account_lastname"]); 57 } 58 59 $callfrom_company_all_list[] = array(0 , "------------------"); 60 $GLOBALS['phpgw']->db->query("SELECT DISTINCT org_name FROM phpgw_addressbook ORDER BY org_name",__LINE__,__FILE__); 61 while($GLOBALS['phpgw']->db->next_record()) 62 { 63 list($company_name) = $GLOBALS['phpgw']->db->Record; 64 $callfrom_company_all_list[] = array($company_name, $company_name); 65 } 66 $GLOBALS['phpgw']->db->free(); 67 $callfrom_person_one_list[] = array(0, "---------------------"); 68 69 $callfrom_person_all_list[] = array(0, "---------------------"); 70 $GLOBALS['phpgw']->db->query("SELECT id, n_given, n_middle, n_family FROM phpgw_addressbook ORDER BY n_family",__LINE__,__FILE__); 71 while($GLOBALS['phpgw']->db->next_record()) 72 { 73 list($ab_id, $ab_firstname, $ab_middle, $ab_lastname) = $GLOBALS['phpgw']->db->Record; 74 $callfrom_person_all_list[] = array($ab_id, $ab_firstname . " " . $ab_middle ." ".$ab_lastname); 75 } 76 $GLOBALS['phpgw']->db->free(); 77 78 // END PREPARE LISTS 79 80 function prepForDb() 81 { 82 global $callfrom_type, $callfrom_person_all, $callfrom_person_one; 83 global $calldate_year, $calldate_month, $calldate_day, $calldate_hour, $calldate_minute; 84 global $callfrom_txt, $calldesc_short, $calldesc_long; 85 global $tmp_callfrom_id, $tmp_calldate; 86 // Handle caller id 87 if($callfrom_type==0) 88 $tmp_callfrom_id = $callfrom_person_all; 89 elseif($callfrom_type==1) 90 $tmp_callfrom_id = $callfrom_person_one; 91 else 92 $tmp_callfrom_id = 0; 93 94 // Format time 95 $tmp_calldate = mktime($calldate_hour,$calldate_minute,$calldate_second,$calldate_month,$calldate_day,$calldate_year); 96 } 97 98 if ($querytype == "INSERT") 99 { 100 prepForDb(); 101 $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_phonelog_entry (pl_callfrom_id, pl_callfrom_txt, pl_callfor, " 102 . "pl_calldate, pl_status, pl_desc_short, pl_desc_long) VALUES ($tmp_callfrom_id," 103 . "'$callfrom_txt', '$callfor', '$tmp_calldate', $callstatus, '$calldesc_short'," 104 . "'$calldesc_long')",__LINE__,__FILE__); 105 Header("Location: " . $GLOBALS['phpgw']->link("/phonelog/index.php")); 106 } 107 if ($querytype == "UPDATE") 108 { 109 prepForDb(); 110 $GLOBALS['phpgw']->db->query("UPDATE phpgw_phonelog_entry SET pl_callfrom_id=$tmp_callfrom_id, pl_callfrom_txt='$callfrom_txt', pl_callfor='$callfor', pl_calldate='$tmp_calldate', pl_status=$callstatus, pl_desc_short='$calldesc_short', pl_desc_long='$calldesc_long' WHERE pl_id=$callid",__LINE__,__FILE__); 111 Header("Location: " . $GLOBALS['phpgw']->link("/phonelog/")); 112 } 113 114 if ($querytype == "NEW") 115 { 116 $calldate_month = date("n"); 117 $calldate_day = date("j"); 118 $calldate_year = date("Y"); 119 $calldate_hour = date("G"); 120 $calldate_minute = date("i"); 121 $callstatus = 3; // Default to status 3 ('call back') at this moment 122 $callfor = 0; 123 $callfrom_type = 0; 124 $callfrom_txt = ""; 125 $callfrom_person_all = 0; 126 $callfrom_company_one = ""; 127 $callfrom_company_all = 0; 128 $callfrom_person_one = 0; 129 $calldesc_short = ""; 130 $calldesc_long = ""; 131 132 $querytype_new = "INSERT"; 133 } 134 if ($querytype == "CALLFROMSELECTED") 135 { 136 if($callfrom_type == 0) 137 { 138 $callfrom_company_all = 0; 139 $callfrom_person_one = 0; 140 $GLOBALS['phpgw']->db->query("SELECT org_name FROM phpgw_addressbook WHERE id=".$callfrom_person_all,__LINE__,__FILE__); 141 $GLOBALS['phpgw']->db->next_record(); 142 list($callfrom_company_one) = $GLOBALS['phpgw']->db->Record; 143 $GLOBALS['phpgw']->db->free(); 144 } 145 elseif($callfrom_type == 1) 146 { 147 $callfrom_person_all = 0; 148 $callfrom_company_one = ""; 149 $GLOBALS['phpgw']->db->query("SELECT id, fn FROM phpgw_addressbook WHERE " 150 . "org_name='".$callfrom_company_all."' ORDER BY n_family",__LINE__,__FILE__); 151 while($GLOBALS['phpgw']->db->next_record()) 152 { 153 list($ab_id, $ab_fullname) = $GLOBALS['phpgw']->db->Record; 154 $callfrom_person_one_list[] = array($ab_id, $ab_fullname); 155 } 156 } 157 else 158 { 159 $callfrom_person_all = 0; 160 $callfrom_company_one = ""; 161 $callfrom_company_all = 0; 162 $callfrom_person_one = 0; 163 } 164 165 if($callid) 166 { 167 $querytype_new = "UPDATE"; 168 } 169 else 170 { 171 $querytype_new = "INSERT"; 172 } 173 } 174 if($querytype=="SELECT") 175 { 176 $GLOBALS['phpgw']->db->query("SELECT pl_callfrom_id, pl_callfrom_txt, pl_callfor, YEAR(pl_calldate), " 177 . "MONTH(pl_calldate), DAYOFMONTH(pl_calldate), HOUR(pl_calldate), " 178 . "MINUTE(pl_calldate), pl_status, pl_desc_short, pl_desc_long FROM " 179 . "phpgw_phonelog_entry WHERE pl_id=$callid",__LINE__,__FILE__); 180 $GLOBALS['phpgw']->db->next_record(); 181 list($callfrom_person_all, $callfrom_txt, $callfor, $calldate_year, $calldate_month, $calldate_day, $calldate_hour, $calldate_minute, $callstatus, $calldesc_short, $calldesc_long) = $GLOBALS['phpgw']->db->Record; 182 $GLOBALS['phpgw']->db->free(); 183 // Set callfrom 184 $callfrom_person_one = 1; 185 $callfrom_company_all = 0; 186 if($callfrom_person_all) 187 { 188 $callfrom_type = 0; 189 if($GLOBALS['phpgw_info']["apps"]["timetrack"]["enabled"]) 190 { 191 $GLOBALS['phpgw']->db->query("SELECT company_name FROM addressbook, customers WHERE company_id=ab_company_id AND ab_id=".$callfrom_person_all,__LINE__,__FILE__); 192 } 193 else 194 { 195 $GLOBALS['phpgw']->db->query("SELECT ab_company FROM addressbook WHERE ab_id=".$callfrom_person_all,__LINE__,__FILE__); 196 } 197 $GLOBALS['phpgw']->db->next_record(); 198 list($callfrom_company_one) = $GLOBALS['phpgw']->db->Record; 199 $GLOBALS['phpgw']->db->free(); 200 } 201 else 202 { 203 $callfrom_type = 2; 204 $callfrom_company_one = ""; 205 $callfrom_person_all = 0; 206 } 207 $querytype_new="UPDATE"; 208 } 209 210 $lang_phonelog_action = lang("phone log - add"); 211 $lang_callstatus = lang("status"); 212 $lang_calldate = lang("call came in at"); 213 $lang_callfrom = lang("call from"); 214 $lang_by_person = lang("by person"); 215 $lang_by_company = lang("by company"); 216 $lang_by_txt = lang("as free text"); 217 $lang_callfor = lang("call for"); 218 $lang_desclong = lang("description"); 219 $lang_descshort = lang("summary"); 220 $lang_addsubmitb = lang("Add"); 221 $lang_addresetb = lang("Clear Form"); 222?> 223 224<p> <?php echo $lang_phonelog_action ?><br> 225 <hr noshade width="98%" align="center" size="1"> 226 227 <script> 228 function doShowCustomerDetails(inForm) { 229 inForm.querytype.value = "CALLFROMSELECTED"; 230 inForm.submit(); 231 } 232 </script> 233 <center> 234<form name="editform" action="<?php echo $GLOBALS['phpgw']->link("/phonelog/editentry.php"); ?>" method="POST"> 235<input type="hidden" name="callid" value="<?php echo $callid ?>"> 236<input type="hidden" name="querytype" value="<?php echo $querytype_new ?>"> 237 <table width="75%" border="0" cellspacing="0" cellpadding="0"> 238 <tr> 239<td rowspan="3" valign=top><?php echo $lang_callfrom ?>:</td> 240 <td> 241<?php echo $lang_by_person ?> : 242 </td> 243 <td> 244<input type=radio name="callfrom_type" value="0" <?php if(!$callfrom_type) echo "CHECKED" ?>> 245 <select name="callfrom_person_all" size="1" onFocus="this.form.callfrom_type[0].checked = true;" onChange="doShowCustomerDetails(this.form);"> 246<?php echo printSelectList($callfrom_person_all, $callfrom_person_all_list) ?> 247 </select> 248 </td> 249 <td> 250<input type=text name="callfrom_company_one" READONLY value="<?php echo $callfrom_company_one ?>"> 251 </td> 252 </tr> 253 <tr> 254 <td> 255<?php echo $lang_by_company ?> 256 </td> 257 <td> 258<input type=radio name="callfrom_type" value="1" <?php if($callfrom_type==1) echo "CHECKED" ?>> 259 <select name="callfrom_company_all" size="1" onFocus="this.form.callfrom_type[1].checked = true;" onChange="doShowCustomerDetails(this.form);"> 260<?php echo printSelectList($callfrom_company_all, $callfrom_company_all_list) ?> 261 </select> 262 </td> 263 <td width="50%"> 264 <select name="callfrom_person_one"> 265<?php echo printSelectList($callfrom_person_one, $callfrom_person_one_list) ?> 266 </select> 267 </td> 268 </tr> 269 <tr> 270 <td> 271<?php echo $lang_by_txt ?> 272 </td> 273 <td colspan="2"> 274<input type=radio name="callfrom_type" value="2" <?php if($callfrom_type==2) echo "CHECKED" ?>> 275<input type="text" value="<?php echo $callfrom_txt ?>" onFocus="this.form.callfrom_type[2].checked = true;" name="callfrom_txt" size="20" maxlength="255"> 276 </td> 277 </tr> 278 <tr> 279<td><?php echo $lang_callstatus ?>:</td> 280 <td colspan="3"> 281 <select name="callstatus"> 282<?php echo printSelectList($callstatus, $callstatus_list) ?> 283 </select> 284 </td> 285 </tr> 286 <tr> 287<td><?php echo $lang_callfor ?>:</td> 288 <td colspan="3"> 289 <select name="callfor"> 290<?php echo printSelectList($callfor, $callfor_list) ?> 291 </select> 292 </td> 293 </tr> 294 <tr> 295<td><?php echo $lang_calldate ?>:</td> 296 <td colspan="3"> 297 <?php 298 $day = '<input type="text" name="calldate_day" value="' . $calldate_day . '" size="2" maxlength="2">'; 299 $month = '<SELECT name="calldate_month" size="1">' 300 . printSelectList($calldate_month, $calldate_month_list) 301 . '</SELECT>'; 302 $year ='<input type="text" name="calldate_year" value="' . $calldate_year . '" size="4" maxlength="4">'; 303 304 echo $GLOBALS['phpgw']->common->dateformatorder($year,$month,$day,True); 305 ?> 306 - 307<input type="text" name="calldate_hour" value="<?php echo $calldate_hour ?>" size="2" maxlength="2">: 308<input type="text" name="calldate_minute" value="<?php echo $calldate_minute ?>" size="2" maxlength="2"> 309 </td> 310 </tr> 311 <tr> 312 <td colspan="4"> </td> 313 </tr> 314 <tr> 315<td><?php echo $lang_descshort ?>:</td> 316<td colspan="3"><input type="text" name="calldesc_short" size="60" maxlength="255" value="<?php echo $calldesc_short ?>"></td> 317 </tr> 318 <tr> 319<td><?php echo $lang_desclong ?>:</td> 320<td colspan="3"><textarea name="calldesc_long" cols="50" rows="5"><?php echo $calldesc_long ?></textarea></td> 321 </tr> 322 </table> 323<?php if($querytype_new=="INSERT") : ?> 324 <input type="submit" value="Add"> 325<?php elseif($querytype_new=="UPDATE") : ?> 326 <input type="submit" value="Update"> 327<?php endif ?> 328 </form> 329 </center> 330 331<?php 332 $GLOBALS['phpgw']->common->phpgw_footer(); 333?> 334