12 $monLibrary= dirname(__FILE__) .
"/../library";
13 $monIncludes= dirname(__FILE__) .
"/../includes";
14 $sharedLibrary= dirname(__FILE__) .
"/../../shared/library";
15 require_once(
"$monLibrary/cu_top.i");
16 require_once(
"$monLibrary/ck_hticket.i");
17 require_once(
"$monIncludes/cu_remote_top.prg");
18 require_once (
"$sharedLibrary/errormail.i");
21 header(
'Content-Type: application/json');
23 if (!CheckPerm($link, $Hu, basename($_SERVER[
'SCRIPT_NAME']), $_SERVER[
'REMOTE_ADDR'])) {
26 throw new Exception (
"Permissions violation");
30 $dms_ok = array(
'action'=>
'string' );
38 $fp = fopen(
"/tmp/miketest",
"w");
40 fwrite( $fp, print_r( $_REQUEST,
true ) );
44 fwrite( $fp,
"\naction = $action" );
48 fwrite( $fp,
"\ntime = " . date(
"m/d/Y g:ia" ) );
51 $jTableResult = Array();
56 $sql =
"SELECT c.*, ci.name 58 INNER JOIN cuinfo ci ON ci.user_name = c.user_name 59 ORDER BY c.enteredon asc ";
60 $impRs = db_query($sql, $dbh);
63 fwrite( $fp,
"\nsql = $sql" );
68 while ( $impRow = db_fetch_assoc( $impRs, $rowcnt++ ) ) {
70 $Intermediate = implode(
"", $impRow );
72 fwrite( $fp,
"\nIntermediate = " . $Intermediate );
75 $md5 = md5($Intermediate);
77 fwrite( $fp,
"\nmd5 = $md5" );
81 $impList = array(
"impid"=>$impRow[
"impid"],
"md5hash"=>$md5,
82 "cuCode"=>$impRow[
"user_name"],
"impStatus"=>$impRow[
"productstatus"],
83 "cuName"=>trim($impRow[
"name"]),
"author"=>$impRow[
"author"],
84 "cuProduct"=>$impRow[
"product"],
"enteredOn"=>$impRow[
"enteredon"],
85 "billedMonthly"=>$impRow[
"billedmonthly"],
"developer"=>$impRow[
"developer"],
86 "targetDate"=>$impRow[
"imptargetdate"],
"startOn"=>$impRow[
"impstarton"],
87 "finishOn"=>$impRow[
"impfinishon"],
"billedSetup"=>$impRow[
"billedsetup"],
88 "vendor"=>$impRow[
"productvendor"] );
89 $jTableResult[] = $impList;
95 $sql =
"SELECT user_name, name 97 WHERE (system_options & $SYS_TYPE_CLOSED) = 0 98 ORDER BY lower(name) ";
99 $cuRs = db_query($sql, $dbh);
103 while ( $Row = db_fetch_assoc( $cuRs, $rowcnt++ ) ) {
104 $jTableResult[] = array(
"cuCode"=>trim($Row[
"user_name"]),
"cuName"=>trim($Row[
"name"]) );
108 fwrite( $fp,
"\njTableResult = " . print_r( $jTableResult,
true ) );
111 case "reademployees":
112 $sql =
"SELECT user_name 114 ORDER BY user_name ";
115 $cuRs = db_query($sql, $dbh);
119 $jTableResult[] = array(
"cuEmployee"=>
"Unassigned" );
120 while ( $Row = db_fetch_assoc( $cuRs, $rowcnt++ ) ) {
121 $jTableResult[] = array(
"cuEmployee"=>trim($Row[
"user_name"]) );
127 $sql =
"SELECT ssovendor 130 $cuRs = db_query($sql, $dbh);
134 $jTableResult[] = array(
"cuVendor"=>
"N/A" );
135 while ( $Row = db_fetch_assoc( $cuRs, $rowcnt++ ) ) {
136 $jTableResult[] = array(
"cuVendor"=>trim($Row[
"ssovendor"]) );
143 $impId = isset( $_REQUEST[
"impid"] ) && ctype_digit( $_REQUEST[
"impid"] ) ? $_REQUEST[
"impid"] : 0;
146 throw new Exception (
"Invalid identifier");
150 $sql =
"SELECT c.*, ci.name 152 INNER JOIN cuinfo ci ON ci.user_name = c.user_name 153 WHERE impid = " . $impId;
154 $impRs = db_query($sql, $dbh);
156 fwrite( $fp,
"\nsql = " . $sql );
159 $impRow = db_fetch_assoc($impRs);
161 $Intermediate = implode(
"", $impRow );
163 fwrite( $fp,
"\nIntermediate = " . $Intermediate );
166 $md5 = md5($Intermediate);
168 fwrite( $fp,
"\nmd5 = " . $md5 );
172 $md5Hash = isset( $_REQUEST[
"md5hash"] ) && ctype_alnum( $_REQUEST[
"md5hash"] ) ? $_REQUEST[
"md5hash"] :
"";
174 if ( !strlen($md5Hash) ) {
175 throw new Exception (
"Missing comparison hash");
178 if ( $md5 == $md5Hash ) {
179 $cuCode = isset( $_REQUEST[
"cuCode"] ) && ctype_alnum( $_REQUEST[
"cuCode"] ) ? $_REQUEST[
"cuCode"] :
"";
180 $impStatus = isset( $_REQUEST[
"impStatus"] ) && ctype_print( $_REQUEST[
"impStatus"] ) ? $_REQUEST[
"impStatus"] :
"New";
181 $author = isset( $_REQUEST[
"author"] ) && ctype_alnum( $_REQUEST[
"author"] ) ? $_REQUEST[
"author"] :
"Unassigned";
182 $cuProduct = isset( $_REQUEST[
"cuProduct"] ) && ctype_print( $_REQUEST[
"cuProduct"] ) ? $_REQUEST[
"cuProduct"] :
"Unassigned";
183 $developer = isset( $_REQUEST[
"developer"] ) && ctype_alnum( $_REQUEST[
"developer"] ) ? $_REQUEST[
"developer"] :
"Unassigned";
184 $vendor = isset( $_REQUEST[
"vendor"] ) && ctype_print( $_REQUEST[
"vendor"] ) ? $_REQUEST[
"vendor"] :
"N/A";
187 if ( isset( $_REQUEST[
"enteredOn"] ) && is_string( $_REQUEST[
"enteredOn"] ) && strlen( $_REQUEST[
"enteredOn"] ) )
188 $enteredOn = date(
"'Y-m-d'", strtotime( $_REQUEST[
"enteredOn"] ) );
191 $enteredOn = date(
"'Y-m-d'" );
193 if ( isset( $_REQUEST[
"targetDate"] ) && is_string( $_REQUEST[
"targetDate"] ) && strlen( $_REQUEST[
"targetDate"] ) )
194 $targetDate = date(
"'Y-m-d'", strtotime( $_REQUEST[
"targetDate"] ) );
197 $targetDate =
"null";
199 if ( isset( $_REQUEST[
"startOn"] ) && is_string( $_REQUEST[
"startOn"] ) && strlen( $_REQUEST[
"startOn"] ) )
200 $startOn = date(
"'Y-m-d'", strtotime( $_REQUEST[
"startOn"] ) );
205 if ( isset( $_REQUEST[
"finishOn"] ) && is_string( $_REQUEST[
"finishOn"] ) && strlen( $_REQUEST[
"finishOn"] ) )
206 $finishOn = date(
"'Y-m-d'", strtotime( $_REQUEST[
"finishOn"] ) );
211 if ( isset( $_REQUEST[
"billedSetup"] ) && is_string( $_REQUEST[
"billedSetup"] ) && strlen( $_REQUEST[
"billedSetup"] ) )
212 $billedSetup = date(
"'Y-m-d'", strtotime( $_REQUEST[
"billedSetup"] ) );
214 $billedSetup =
"null";
217 if ( isset( $_REQUEST[
"billedMonthly"] ) && is_string( $_REQUEST[
"billedMonthly"] ) && strlen( $_REQUEST[
"billedMonthly"] ) )
218 $billedMonthly = date(
"'Y-m-d'", strtotime( $_REQUEST[
"billedMonthly"] ) );
220 $billedMonthly =
"null";
225 $errorList = array();
226 if ( !strlen( $cuCode ) ) $errorList[] =
"Invalid CU Code";
228 if ( count( $errorList ) > 0 ) {
229 $errorString = implode(
"\n", $errorList );
230 throw new Exception ($errorString);
233 $sql =
"UPDATE cuprodimpstat SET 234 user_name = '$cuCode', 235 productstatus = '$impStatus', 237 product = '$cuProduct', 238 enteredon = $enteredOn, 239 billedsetup = $billedSetup, 240 developer = '$developer', 241 imptargetdate = $targetDate, 242 impstarton = $startOn, 243 impfinishon = $finishOn, 244 billedmonthly = $billedMonthly, 245 productvendor = '$vendor' 246 WHERE impid = $impId ";
247 $upd_rs = db_query ($sql, $dbh);
250 fwrite( $fp,
"\nupdate sql = " . $sql );
253 throw new Exception (
"Error Updating Record for $cuCode");
256 $sql =
"SELECT c.*, ci.name 258 INNER JOIN cuinfo ci ON ci.user_name = c.user_name 259 WHERE impid = " . $impId;
260 $impRs = db_query($sql, $dbh);
263 fwrite( $fp,
"\nsql = " . $sql );
266 $impRow = db_fetch_assoc($impRs);
268 $Intermediate = implode(
"", $impRow );
270 fwrite( $fp,
"\nIntermediate = " . $Intermediate );
273 $md5 = md5($Intermediate);
276 $impList = array(
"impid"=>$impRow[
"impid"],
"md5hash"=>$md5,
277 "cuCode"=>$impRow[
"user_name"],
"impStatus"=>$impRow[
"productstatus"],
278 "cuName"=>trim($impRow[
"name"]),
"author"=>$impRow[
"author"],
279 "cuProduct"=>$impRow[
"product"],
"enteredOn"=>$impRow[
"enteredon"],
280 "billedMonthly"=>$impRow[
"billedmonthly"],
"developer"=>$impRow[
"developer"],
281 "targetDate"=>$impRow[
"imptargetdate"],
"startOn"=>$impRow[
"impstarton"],
282 "finishOn"=>$impRow[
"impfinishon"],
"billedSetup"=>$impRow[
"billedsetup"],
283 "vendor"=>$impRow[
"productvendor"] );
285 $jTableResult[] = $impList;
289 $impList = array(
"impid"=>$impRow[
"impid"],
"md5hash"=>$md5,
290 "cuCode"=>$impRow[
"user_name"],
"impStatus"=>$impRow[
"productstatus"],
291 "cuName"=>trim($impRow[
"name"]),
"author"=>$impRow[
"author"],
292 "cuProduct"=>$impRow[
"product"],
"enteredOn"=>$impRow[
"enteredon"],
293 "billedMonthly"=>$impRow[
"billedmonthly"],
"developer"=>$impRow[
"developer"],
294 "targetDate"=>$impRow[
"imptargetdate"],
"startOn"=>$impRow[
"impstarton"],
295 "finishOn"=>$impRow[
"impfinishon"],
"billedSetup"=>$impRow[
"billedsetup"],
296 "vendor"=>$impRow[
"productvendor"] );
298 $jTableResult[
"error"] =
"One or more values changed prior to update. Please refresh page and re-enter values.";
299 $jTableResult[] = $impList;
304 $cuCode = isset( $_REQUEST[
"cuCode"] ) && ctype_alnum( $_REQUEST[
"cuCode"] ) ? $_REQUEST[
"cuCode"] :
"";
305 $impStatus = isset( $_REQUEST[
"impStatus"] ) && ctype_print( $_REQUEST[
"impStatus"] ) ? $_REQUEST[
"impStatus"] :
"New";
306 $author = isset( $_REQUEST[
"author"] ) && ctype_alnum( $_REQUEST[
"author"] ) ? $_REQUEST[
"author"] :
"Unassigned";
307 $cuProduct = isset( $_REQUEST[
"cuProduct"] ) && ctype_alnum( $_REQUEST[
"cuProduct"] ) ? $_REQUEST[
"cuProduct"] :
"Unassigned";
308 $developer = isset( $_REQUEST[
"developer"] ) && ctype_alnum( $_REQUEST[
"developer"] ) ? $_REQUEST[
"developer"] :
"Unassigned";
309 $vendor = isset( $_REQUEST[
"vendor"] ) && ctype_print( $_REQUEST[
"vendor"] ) ? $_REQUEST[
"vendor"] :
"N/A";
312 if ( isset( $_REQUEST[
"enteredOn"] ) && is_string( $_REQUEST[
"enteredOn"] ) && strlen( $_REQUEST[
"enteredOn"] ) )
313 $enteredOn = date(
"'Y-m-d'", strtotime( $_REQUEST[
"enteredOn"] ) );
316 $enteredOn = date(
"'Y-m-d'" );
318 if ( isset( $_REQUEST[
"targetDate"] ) && is_string( $_REQUEST[
"targetDate"] ) && strlen( $_REQUEST[
"targetDate"] ) )
319 $targetDate = date(
"'Y-m-d'", strtotime( $_REQUEST[
"targetDate"] ) );
322 $targetDate =
"null";
324 if ( isset( $_REQUEST[
"startOn"] ) && is_string( $_REQUEST[
"startOn"] ) && strlen( $_REQUEST[
"startOn"] ) )
325 $startOn = date(
"'Y-m-d'", strtotime( $_REQUEST[
"startOn"] ) );
332 $billedSetup =
"null";
333 $billedMonthly =
"null";
336 $errorList = array();
337 if ( !strlen( $cuCode ) ) $errorList[] =
"Invalid CU Code";
339 if ( count( $errorList ) ) {
340 $errorString = implode(
"\n", $errorList );
341 throw new Exception ($errorString);
345 $sql =
"SELECT nextval('cuprodimpstat_impid_seq') as impid";
346 $impRs = db_query($sql, $dbh);
347 $impRow = db_fetch_assoc($impRs);
348 $impId = $impRow[
"impid"];
352 $sql =
"INSERT INTO cuprodimpstat 353 ( impid, user_name, productstatus, author, product, 354 enteredon, developer, imptargetdate, impstarton, 355 impfinishon, productvendor, billedsetup, billedmonthly, createdon, 359 '" . prep_save($cuCode, 12) .
"', 360 '" . prep_save($impStatus, 10) .
"', 361 '" . prep_save($author, 12) .
"', 362 '" . prep_save($cuProduct, 30) .
"', 364 '" . prep_save($developer, 12) .
"', 368 '" . prep_save($vendor, 20) .
"', 369 " . $billedSetup .
", 370 " . $billedMonthly .
", 371 '" . date(
"Y-m-d G:i:s" ) .
"', 372 '" . prep_save($Hu, 12) .
"')";
374 fwrite( $fp,
" create: $sql" );
377 $updRs = db_query( $sql, $dbh );
379 throw new Exception (
"Error Inserting Product Feature Status Record");
383 $sql =
"SELECT c.*, ci.name 385 INNER JOIN cuinfo ci ON ci.user_name = c.user_name 386 WHERE impid = " . $impId;
387 $impRs = db_query($sql, $dbh);
390 fwrite( $fp,
"\nsql = " . $sql );
393 $impRow = db_fetch_assoc($impRs);
395 $Intermediate = implode(
"", $impRow );
397 fwrite( $fp,
"\nIntermediate = " . $Intermediate );
400 $md5 = md5($Intermediate);
403 $impList = array(
"impid"=>$impRow[
"impid"],
"md5hash"=>$md5,
404 "cuCode"=>$impRow[
"user_name"],
"impStatus"=>$impRow[
"productstatus"],
405 "cuName"=>trim($impRow[
"name"]),
"author"=>$impRow[
"author"],
406 "cuProduct"=>$impRow[
"product"],
"enteredOn"=>$impRow[
"enteredon"],
407 "billedMonthly"=>$impRow[
"billedmonthly"],
"developer"=>$impRow[
"developer"],
408 "targetDate"=>$impRow[
"imptargetdate"],
"startOn"=>$impRow[
"impstarton"],
409 "finishOn"=>$impRow[
"impfinishon"],
"billedSetup"=>$impRow[
"billedsetup"],
410 "vendor"=>$impRow[
"productvendor"] );
412 $jTableResult[] = $impList;
420 $impId = isset( $_REQUEST[
"impid"] ) && ctype_digit( $_REQUEST[
"impid"] ) ? $_REQUEST[
"impid"] : 0;
425 WHERE impid = " . $impId;
426 $impRs = db_query($sql, $dbh);
428 $impRow = db_fetch_assoc( $impRs );
430 switch ( $impRow[
"productstatus"] ) {
432 $newDeveloper = ( $impRow[
"developer"] ==
"Unassigned") ? $Hu : $impRow[
"developer"];
433 $newStatus =
"In Devel";
434 $startOn = date(
'Y-m-d' );
436 $sql =
"UPDATE cuprodimpstat SET 437 developer = '$newDeveloper', 438 productstatus = '$newStatus', 439 impstarton = '$startOn' 440 WHERE impId = $impId";
441 db_query($sql, $dbh);
444 $newStatus =
"In Review";
446 $sql =
"UPDATE cuprodimpstat SET 447 productstatus = '$newStatus' 448 WHERE impId = $impId";
449 db_query($sql, $dbh);
452 $newStatus =
"Published";
453 $finishOn = date(
'Y-m-d' );
455 $sql =
"UPDATE cuprodimpstat SET 456 productstatus = '$newStatus', 457 impfinishon = '$finishOn' 458 WHERE impId = $impId";
459 db_query($sql, $dbh);
462 SendNoticeToOwner( $impId,
"prebill",
"Product Feature is published" );
465 $newStatus =
"Bill Setup";
467 $sql =
"UPDATE cuprodimpstat SET 468 productstatus = '$newStatus' 469 WHERE impId = $impId";
470 db_query($sql, $dbh);
473 SendNoticeToOwner( $impId,
"billing",
"Product Feature ready for billing" );
476 $newStatus =
"Bill Month";
477 $billDate = date(
'Y-m-d' );
479 $sql =
"UPDATE cuprodimpstat SET 480 productstatus = '$newStatus', 481 billedsetup = '$billDate' 482 WHERE impId = $impId";
483 db_query($sql, $dbh);
486 $newStatus =
"Complete";
487 $billDate = date(
'Y-m-d' );
489 $sql =
"UPDATE cuprodimpstat SET 490 productstatus = '$newStatus', 491 billedmonthly = '$billDate' 492 WHERE impId = $impId";
493 db_query($sql, $dbh);
502 fwrite( $fp,
"\nsql = " . $sql );
512 print json_encode($jTableResult);
517 $jTableResult = array();
518 $jTableResult[
"error"] = $ex->getMessage();
519 print json_encode($jTableResult);
523 fwrite( $fp,
"\n" . json_encode($jTableResult) );
528 function SendNoticeToOwner( $impId, $owner, $subjectStart ) {
534 WHERE impid = '$impId' ";
536 if ( $rs = db_query( $sql, $dbh ) ) {
537 $productRow = db_fetch_array( $rs );
539 $cuCode = $productRow[
"user_name"];
540 $cuProduct = $productRow[
"product"];
543 $sql =
"SELECT $owner 545 WHERE home_cu_code = '$cuProduct' ";
547 if ( $rs = db_query( $sql, $dbh ) ) {
548 $ownerRow = db_fetch_array( $rs );
550 $owner = trim( $ownerRow[
"$owner"] );
551 if ( strlen( $owner ) ) {
553 SendNotice( $owner, $cuCode, $cuProduct, $subjectStart );
561 function SendNotice( $empName, $cuCode, $cuProduct, $subjectStart ) {
567 WHERE user_name = '$empName' ";
568 $notifyRS = db_query( $sql, $dbh );
570 if ( $notifyRS !== FALSE ) {
572 $notifyRow = db_fetch_array( $notifyRS );
573 if ( trim($notifyRow[
'notifyemail']) !==
'' ) {
574 $notifySendTo = trim($notifyRow[
'notifyemail']);
579 WHERE user_name = '$Hu' ";
580 $authorRS = db_query($sql, $dbh);
581 $authorRow = db_fetch_array($authorRS);
582 if ( trim( $authorRow[
'notifyemail'] ) !=
'' ) {
583 $notifySendFrm = trim( $authorRow[
'notifyemail'] );
585 $notifySendFrm =
"nobody@homecu.net";
591 WHERE user_name = '$cuCode' ";
592 $nameRS = db_query( $sql, $dbh );
593 $nameRow = db_fetch_array($nameRS);
595 $sql =
"SELECT home_cu_desc 597 WHERE home_cu_code = '$cuProduct' ";
598 $productRS = db_query( $sql, $dbh );
599 $productRow = db_fetch_array( $productRS );
601 $notifySubject =
"$subjectStart: $cuProduct for $cuCode.";
605 $notifyMessage .=
"CU: " . trim( $nameRow[
"name"] ) .
" (" . $cuCode .
")\n";
606 $notifyMessage .=
"Service: " . $productRow[
"home_cu_desc"] .
"\n\n";
607 $notifyMessage .=
"Entered by $Hu\n";
608 $notifyMessage .= date(
"m/d/y g:ia" );
611 $notify->mailto = $notifySendTo;
612 $notify->replyto = $notifySendFrm;
613 $notify->mailfrom = $notifySendFrm;
615 $notify->subject = $notifySubject;
616 $notify->msgbody = $notifyMessage;
617 $notify->callingfunction = __FUNCTION__;
618 $notify->file = __FILE__;
619 $notify->cu = $cuCode;