1<?php 2/* 3 FusionPBX 4 Version: MPL 1.1 5 6 The contents of this file are subject to the Mozilla Public License Version 7 1.1 (the "License"); you may not use this file except in compliance with 8 the License. You may obtain a copy of the License at 9 http://www.mozilla.org/MPL/ 10 11 Software distributed under the License is distributed on an "AS IS" basis, 12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 13 for the specific language governing rights and limitations under the 14 License. 15 16 The Original Code is FusionPBX 17 18 The Initial Developer of the Original Code is 19 Mark J Crane <markjcrane@fusionpbx.com> 20 Portions created by the Initial Developer are Copyright (C) 2008-2015 21 the Initial Developer. All Rights Reserved. 22 23 Contributor(s): 24 Mark J Crane <markjcrane@fusionpbx.com> 25*/ 26require_once "root.php"; 27require_once "resources/require.php"; 28require_once "resources/check_auth.php"; 29if (!permission_exists('contact_time_add')) { echo "access denied"; exit; } 30 31//add multi-lingual support 32 $language = new text; 33 $text = $language->get(); 34 35//get contact uuid 36 $domain_uuid = check_str($_REQUEST['domain_uuid']); 37 $contact_uuid = check_str($_REQUEST['contact_uuid']); 38 39//get posted variables & set time status 40 if (sizeof($_POST) > 0) { 41 $contact_time_uuid = check_str($_POST['contact_time_uuid']); 42 $contact_uuid = check_str($_POST['contact_uuid']); 43 $time_action = check_str($_POST['time_action']); 44 $time_description = check_str($_POST['time_description']); 45 46 if ($time_description == 'Description...') { unset($time_description); } 47 48 if ($time_action == 'start') { 49 $contact_time_uuid = uuid(); 50 $sql = "insert into v_contact_times "; 51 $sql .= "( "; 52 $sql .= "domain_uuid, "; 53 $sql .= "contact_time_uuid, "; 54 $sql .= "contact_uuid, "; 55 $sql .= "user_uuid, "; 56 $sql .= "time_start, "; 57 $sql .= "time_description "; 58 $sql .= ") "; 59 $sql .= "values "; 60 $sql .= "( "; 61 $sql .= "'".$domain_uuid."', "; 62 $sql .= "'".$contact_time_uuid."', "; 63 $sql .= "'".$contact_uuid."', "; 64 $sql .= "'".$_SESSION["user"]["user_uuid"]."', "; 65 $sql .= "'".date("Y-m-d H:i:s")."', "; 66 $sql .= "'".$time_description."' "; 67 $sql .= ")"; 68 $db->exec(check_sql($sql)); 69 unset($sql); 70 } 71 if ($time_action == 'stop') { 72 $sql = "update v_contact_times "; 73 $sql .= "set "; 74 $sql .= "time_stop = '".date("Y-m-d H:i:s")."', "; 75 $sql .= "time_description = '".$time_description."' "; 76 $sql .= "where "; 77 $sql .= "contact_time_uuid = '".$contact_time_uuid."' "; 78 $sql .= "and domain_uuid = '".$domain_uuid."' "; 79 $sql .= "and contact_uuid = '".$contact_uuid."' "; 80 $sql .= "and user_uuid = '".$_SESSION["user"]["user_uuid"]."' "; 81 $db->exec(check_sql($sql)); 82 unset($sql); 83 } 84 header("Location: contact_timer.php?domain_uuid=".$domain_uuid."&contact_uuid=".$contact_uuid); 85 } 86 87//get contact details 88 $sql = "select "; 89 $sql .= "contact_organization, "; 90 $sql .= "contact_name_given, "; 91 $sql .= "contact_name_family, "; 92 $sql .= "contact_nickname "; 93 $sql .= "from v_contacts "; 94 $sql .= "where domain_uuid = '".$domain_uuid."' "; 95 $sql .= "and contact_uuid = '".$contact_uuid."' "; 96 $prep_statement = $db->prepare(check_sql($sql)); 97 $prep_statement->execute(); 98 $result = $prep_statement->fetch(PDO::FETCH_NAMED); 99 if (sizeof($result) > 0) { 100 $contact_organization = $result["contact_organization"]; 101 $contact_name_given = $result["contact_name_given"]; 102 $contact_name_family = $result["contact_name_family"]; 103 $contact_nickname = $result["contact_nickname"]; 104 } 105 else { 106 exit; 107 } 108 unset ($sql, $prep_statement, $result); 109 110//determine timer state and action 111 $sql = "select "; 112 $sql .= "contact_time_uuid, "; 113 $sql .= "time_description "; 114 $sql .= "from v_contact_times "; 115 $sql .= "where domain_uuid = '".$domain_uuid."' "; 116 $sql .= "and user_uuid = '".$_SESSION['user']['user_uuid']."' "; 117 $sql .= "and contact_uuid = '".$contact_uuid."' "; 118 $sql .= "and time_start is not null "; 119 $sql .= "and time_stop is null "; 120 $prep_statement = $db->prepare(check_sql($sql)); 121 $prep_statement->execute(); 122 $result = $prep_statement->fetch(PDO::FETCH_NAMED); 123 if (sizeof($result) > 0) { 124 $contact_time_uuid = $result["contact_time_uuid"]; 125 $time_description = $result["time_description"]; 126 } 127 unset ($sql, $prep_statement, $result); 128 129 $timer_state = ($contact_time_uuid != '') ? 'running' : 'stopped'; 130 $timer_action = ($timer_state == 'running') ? 'stop' : 'start'; 131 132//determine contact name to display 133 if ($contact_nickname != '') { 134 $contact = $contact_nickname; 135 } 136 else if ($contact_name_given != '') { 137 $contact = $contact_name_given; 138 } 139 if ($contact_name_family != '') { 140 $contact .= ($contact != '') ? ' '.$contact_name_family : $contact_name_family; 141 } 142 if ($contact_organization != '') { 143 $contact .= ($contact != '') ? ', '.$contact_organization : $contact_organization; 144 } 145?> 146 147<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'> 148<head> 149 <title><?php echo $text['label-time_timer']; ?>: <?php echo $contact; ?></title> 150 <style> 151 body { 152 color: #5f5f5f; 153 font-size: 12px; 154 font-family: arial; 155 margin: 0; 156 padding: 15px; 157 } 158 159 b { 160 color: #952424; 161 font-size: 15px; 162 font-family: arial; 163 } 164 165 a { 166 color: #004083; 167 width: 100%; 168 } 169 170 a:hover { 171 color: #5082ca; 172 } 173 174 form { 175 margin: 0; 176 } 177 178 input.btn, input.button { 179 font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif; 180 padding: 2px 6px 3px 6px; 181 color: #fff; 182 font-weight: bold; 183 cursor: pointer; 184 font-size: 11px; 185 -moz-border-radius: 3px; 186 -webkit-border-radius: 3px; 187 -khtml-border-radius: 3px; 188 border-radius: 3px; 189 background-image: -moz-linear-gradient(top, #524f59 25%, #000 64%); 190 background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0.25, #524f59), color-stop(0.64, #000)); 191 border: 1px solid #26242a; 192 background-color: #000; 193 text-align: center; 194 text-transform: uppercase; 195 text-shadow: 0px 0px 1px rgba(0, 0, 0, 0.85); 196 opacity: 0.9; 197 -moz-opacity: 0.9; 198 } 199 200 input.btn:hover, input.button:hover, img.list_control_icon:hover { 201 box-shadow: 0 0 5px #cddaf0; 202 -webkit-box-shadow: 0 0 5px #cddaf0; 203 -moz-box-shadow: 0 0 5px #cddaf0; 204 opacity: 1.0; 205 -moz-opacity: 1.0; 206 cursor: pointer; 207 } 208 209 input.txt, textarea.txt, select.txt, .formfld { 210 font-family: arial; 211 font-size: 12px; 212 color: #000; 213 text-align: left; 214 padding: 5px; 215 border: 1px solid #c0c0c0; 216 background-color: #fff; 217 box-shadow: 0 0 3px #cddaf0 inset; 218 -moz-box-shadow: 0 0 3px #cddaf0 inset; 219 -webkit-box-shadow: 0 0 3px #cddaf0 inset; 220 border-radius: 3px; 221 -moz-border-radius: 3px; 222 -webkit-border-radius: 3px; 223 } 224 225 input.txt, .formfld { 226 transition: width 0.25s; 227 -moz-transition: width 0.25s; 228 -webkit-transition: width 0.25s; 229 max-width: 500px; 230 } 231 232 input.txt:focus, .formfld:focus { 233 -webkit-box-shadow: 0 0 5px #cddaf0; 234 -moz-box-shadow: 0 0 5px #cddaf0; 235 box-shadow: 0 0 5px #cddaf0; 236 } 237 238 td { 239 color: #5f5f5f; 240 font-size: 12px; 241 font-family: arial; 242 } 243 244 .vncell { 245 border-bottom: 1px solid #fff; 246 background-color: #e5e9f0; 247 padding: 8px; 248 text-align: right; 249 color: #000; 250 -moz-border-radius: 4px; 251 -webkit-border-radius: 4px; 252 border-radius: 4px; 253 border-right: 3px solid #e5e9f0; 254 } 255 256 DIV.timer_running { 257 vertical-align: middle; 258 padding-top: 7px; 259 line-height: 50px; 260 width: 100%; 261 height: 53px; 262 text-align: center; 263 background-color: #2C9DE8; 264 font-size: 50px; 265 color: #FFFFFF; 266 /*-webkit-text-shadow: 0px 0px 5px #000;*/ 267 /*-moz-text-shadow: 0px 0px 5px #000;*/ 268 /*text-shadow: 0px 0px 5px #000;*/ 269 font-weight: bold; 270 letter-spacing: -0.05em; 271 font-family: "Courier New",Courier,"Lucida Sans Typewriter","Lucida Typewriter",monospace; 272 -moz-border-radius: 4px; 273 -webkit-border-radius: 4px; 274 border-radius: 4px; 275 } 276 277 DIV.timer_stopped { 278 vertical-align: middle; 279 padding-top: 7px; 280 line-height: 50px; 281 width: 100%; 282 height: 53px; 283 text-align: center; 284 background-color: #2C9DE8; 285 font-size: 50px; 286 color: #FFFFFF; 287 /*-webkit-text-shadow: 0px 0px 5px #000;*/ 288 /*-moz-text-shadow: 0px 0px 5px #000;*/ 289 /*text-shadow: 0px 0px 5px #000;*/ 290 font-weight: bold; 291 letter-spacing: -0.05em; 292 font-family: "Courier New",Courier,"Lucida Sans Typewriter","Lucida Typewriter",monospace; 293 -moz-border-radius: 4px; 294 -webkit-border-radius: 4px; 295 border-radius: 4px; 296 } 297 298 </style> 299 300 <script language="JavaScript" type="text/javascript" src="<?php echo PROJECT_PATH; ?>/resources/jquery/jquery-1.11.1.js"></script> 301 <script type="text/javascript"> 302 $(document).ready(function(){ 303 //ajax for refresh 304 var refresh = 1500; 305 var source_url = 'contact_timer_inc.php?domain_uuid=<?php echo $domain_uuid; ?>&contact_uuid=<?php echo $contact_uuid; ?>&contact_time_uuid=<?php echo $contact_time_uuid; ?>'; 306 307 var ajax_get = function () { 308 $.ajax({ 309 url: source_url, success: function(response){ 310 $("#ajax_reponse").html(response); 311 } 312 }); 313 setTimeout(ajax_get, refresh); 314 }; 315 <?php if ($timer_state == 'running') { ?> 316 ajax_get(); 317 <?php } ?> 318 }); 319 320 //set window title to time when timer is running 321 function set_title(title_text) { 322 window.document.title = title_text; 323 } 324 325 </script> 326</head> 327<body> 328 <img src='resources/images/icon_timer.png' style='width: 24px; height: 24px; border: none; margin-left: 15px;' alt="<?php echo $text['label-time_timer']; ?>" align='right'> 329 <b><?php echo $text['label-time_timer']; ?></b> 330 <br><br> 331 <?php echo $text['description_timer']; ?> 332 <br><br> 333 <strong><a href="javascript:void(0);" onclick="window.opener.location.href='contact_edit.php?id=<?php echo $contact_uuid; ?>';"><?php echo $contact; ?></a></strong> 334 <br><br> 335 <div id='ajax_reponse' class='timer_<?php echo $timer_state;?>'>00:00:00</div> 336 <br> 337 <form name='frm' id='frm' method='post' action=''> 338 <input type='hidden' name='domain_uuid' value="<?php echo $domain_uuid; ?>"> 339 <input type='hidden' name='contact_time_uuid' value="<?php echo $contact_time_uuid; ?>"> 340 <input type='hidden' name='contact_uuid' value="<?php echo $contact_uuid; ?>"> 341 <input type='hidden' name='time_action' value="<?php echo $timer_action; ?>"> 342 <table cellpadding='0' cellspacing='0' border='0' style='width: 100%;'> 343 <tr> 344 <td class='vncell' style='text-align: center; padding: 10px;'> 345 <?php echo $text['label-description']; ?> 346 <textarea name='time_description' id='timer_description' class='formfld' style='width: 100%; height: 50px; margin-top: 5px;'><?php echo $time_description; ?></textarea> 347 <? if ($timer_state == 'stopped') { ?><script>document.getElementById('timer_description').focus();</script><? } ?> 348 </td> 349 </tr> 350 </table> 351 <br> 352 <center> 353 <?php if ($timer_state == 'running') { ?> 354 <input type='submit' class='btn' value="<?php echo $text['button-stop']; ?>"> 355 <?php } else if ($timer_state == 'stopped') { ?> 356 <input type='submit' class='btn' value="<?php echo $text['button-start']; ?>"> 357 <?php } ?> 358 </center> 359 </form> 360</body> 361</html>