X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=rantest%2Fweb%2Fphp%2FUtils.php;fp=rantest%2Fweb%2Fphp%2FUtils.php;h=fcbde7a640c1cc9e665f731daade2754cc328194;hb=8ec853edfd2e5666d8e76fb58bb95da7b4ccfbf6;hp=0000000000000000000000000000000000000000;hpb=b1f5fe3b3f099b5d0ffbf406dd4bee2c35522813;p=clearscm.git
diff --git a/rantest/web/php/Utils.php b/rantest/web/php/Utils.php
new file mode 100644
index 0000000..fcbde7a
--- /dev/null
+++ b/rantest/web/php/Utils.php
@@ -0,0 +1,376 @@
+DEBUG: $msg
";
+ } // if
+} // debug
+
+function dumpObject ($object) {
+ print "
";
+ print_r ($object);
+ print "
";
+} // dumpObject
+
+function Error ($msg) {
+ print "ERROR: $msg
";
+} // Error
+
+function banner () {
+ $banner = <<
+
+
+ ![General Dynamics C4 Systems](/images/companyLogo.gif) |
+ |
+
+
+END;
+
+ return $banner;
+} // banner
+
+function YMD2MDY ($date) {
+ return substr ($date, 5, 2) . "/" .
+ substr ($date, 8, 2) . "/" .
+ substr ($date, 0, 4);
+} // YMD2MDY
+
+function MDY2YMD ($date) {
+ return substr ($date, 6, 4) . "-" .
+ substr ($date, 0, 2) . "-" .
+ substr ($date, 3, 2);
+} // MDY2YMD
+
+function cmpStr ($a, $b, $field, $direction) {
+ if ($direction == "ascending") {
+ return strcmp ($a[$field], $b[$field]);
+ } else {
+ return strcmp ($b[$field], $a[$field]);
+ } // if
+} // cmpStr
+
+function cmpNbr ($a, $b, $field, $direction) {
+ if ($a[$field] == $b[$field]) {
+ return 0;
+ } // if
+
+ if ($direction == "ascending") {
+ return ($a[$field] < $b[$field]) ? -1 : 1;
+ } else {
+ return ($a[$field] < $b[$field]) ? 1 : -1;
+ } // if
+} // cmpNbr
+
+function getUsername ($userid) {
+ exec ("ypmatch $userid passwd | cut -f5 -d:", &$username);
+
+ if (empty ($username)) {
+ return "Unknown";
+ } else {
+ if ($username[0] == "SWIT account for SWIT testing") {
+ return "pswit";
+ } else {
+ return $username[0];
+ } // if
+ } // if
+} // getUsername
+
+function emailUsersDropdown () {
+ define (DIM, "#888");
+
+ exec ("ypcat passwd | grep ^p|cut -f1,5 -d: | grep -v 'SWIT account'", &$userids);
+
+ $users ["unknown"] = "<Select User>";
+
+ foreach ($userids as $user) {
+ list ($pnbr, $name) = explode (":", $user);
+
+ $users [$pnbr] = $name;
+ } # foreach
+
+ asort ($users);
+
+ $dropdown = "Email to ";
+
+ return $dropdown;
+} // emailUsersDropdown
+
+function copyright () {
+ global $VERSION;
+
+ $year = date ("Y");
+
+ $thisFile = "$_SERVER[DOCUMENT_ROOT]/$_SERVER[PHP_SELF]";
+ $lastModified = date ("F d Y @ g:i a", filemtime ($thisFile));
+
+ print <<
+Rantest Web Version: $VERSION - EAST Automation Team
+Last Modified: $lastModified
+Copyright $year © General Dynamics, all rights reserved
+
Home
+ |
+Wiki
+ |
+Users Guide
+ |
+Usage
+ |
+Other Docs
+
+END;
+} // copyright
+
+function Today2SQLDatetime () {
+ return date ("Y-m-d H:i:s");
+} // Today2SQLDatetime
+
+function FormatDuration ($difference) {
+ $seconds_per_min = 60;
+ $seconds_per_hour = 60 * $seconds_per_min;
+ $seconds_per_day = $seconds_per_hour * 24;
+
+ $days = 0;
+ $hours = 0;
+ $minutes = 0;
+ $seconds = 0;
+
+ if ($difference > $seconds_per_day) {
+ $days = (int) ($difference / $seconds_per_day);
+ $difference = $difference % $seconds_per_day;
+ } // if
+
+ if ($difference > $seconds_per_hour) {
+ $hours = (int) ($difference / $seconds_per_hour);
+ $difference = $difference % $seconds_per_hour;
+ } // if
+
+ if ($difference > $seconds_per_min) {
+ $minutes = (int) ($difference / $seconds_per_min);
+ $difference = $difference % $seconds_per_min;
+ } // if
+
+ $seconds = $difference;
+
+ $day_str = "";
+ $hour_str = "";
+ $min_str = "";
+ $sec_str = "";
+ $duration = "";
+
+ if ($days > 0) {
+ $day_str = $days == 1 ? "1 day" : "$hours days";
+ $duration = $day_str;
+ } // if
+
+ if ($hours > 0) {
+ $hour_str = $hours == 1 ? "1 hr" : "$hours hrs";
+
+ if ($duration != "") {
+ $duration .= " ". $hour_str;
+ } else {
+ $duration = $hour_str;
+ } // if
+ } // if
+
+ if ($minutes > 0) {
+ $min_str = $minutes == 1 ? "1 min" : "$minutes mins";
+
+ if ($duration != "") {
+ $duration .= " " . $min_str;
+ } else {
+ $duration = $min_str;
+ } // if
+ } // if
+
+ if ($seconds > 0) {
+ $sec_str = $seconds == 1 ? "1 sec" : "$seconds secs";
+
+ if ($duration != "") {
+ $duration .= " " . $sec_str;
+ } else {
+ $duration = $sec_str;
+ } // if
+ } // if
+
+ if ($duration == "" and $seconds == 0) {
+ $duration = "under 1 second";
+ } // if
+
+ return $duration;
+} // FormatDuration
+
+function Duration ($start, $end) {
+ $start_timestamp = strtotime ($start);
+ $end_timestamp = strtotime ($end);
+
+ $difference = $end_timestamp - $start_timestamp;
+
+ return FormatDuration ($difference);
+} // Duration
+
+// Returns a string representation of a CSV file given a hash
+// representing the data. If $title is supplied it is made the first
+// line. Next a header row is generated based on the keys of the $data
+// hash. Finally data rows are generated. Any key in the hash
+// beginning with "_" is skipped.
+function exportCSV ($data, $title = "") {
+ if (isset ($title)) {
+ $csv .= "$title\n";
+ } // if
+
+ // Create header line
+ $firstTime = true;
+
+ foreach ($data[0] as $key => $value) {
+ // Skip "hidden" fields - fields beginning with "_"
+ if (preg_match ("/^_/", $key) == 1) {
+ continue;
+ } // if
+
+ if (!$firstTime) {
+ $csv .= ",";
+ } else {
+ $firstTime = false;
+ } // if
+
+ $csv .= "\"$key\"";
+ } // foreach
+
+ $csv .= "\n";
+
+ // Data lines
+ foreach ($data as $entry) {
+ $firstTime = true;
+
+ foreach ($entry as $key => $value) {
+ // Skip "hidden" fields - fields beginning with "_"
+ if (preg_match ("/^_/", $key) == 1) {
+ continue;
+ } // if
+
+ if (!$firstTime) {
+ $csv .= ",";
+ } else {
+ $firstTime = false;
+ } // if
+
+ $csv .= "\"$value\"";
+ } // foreach
+
+ $csv .= "\n";
+ } // foreach
+
+ return $csv;
+} // exportCSV
+
+function getStyleSheets () {
+ $styleSheet = "\n\n";
+
+ return $styleSheet;
+} // getStyleSheets
+
+function mailReport ($pnbr, $username, $subject, $body, $filename, $attachment) {
+ if ($pnbr == "unknown") {
+ return "ERROR: You need to select a user to email to first!
";
+ } // if
+
+ $mimeSeparator = md5 (time ());
+
+ $to = "$username <$pnbr@gdc4s.com>";
+ $toDisplay= "$username <$pnbr@gdc4s.com>";
+
+ $headers = "From: RanTestWeb@gdc4s.com\n";
+ $headers .= "MIME-Version: 1.0\n";
+ $headers .= "X-Mailer: PHP\n";
+ $headers .= "Content-Type: multipart/mixed;\n";
+ $headers .=" boundary=\"$mimeSeparator\"";
+
+ $message = "This is a multi-part message in MIME format.\n";
+ $message .= "--$mimeSeparator\n";
+ $message .= "Content-Type: text/html; charset=ISO-8859-1\n";
+ $message .= "Content-Transfer-Encoding: 7bit\n\n";
+
+ $message .= <<
+
+
+END;
+
+ $message .= getStyleSheets ();
+ $message .= <<
+
+$subject
+END;
+
+ $message .= $body;
+
+ $message .= "\n--$mimeSeparator\n";
+ $message .= "Content-Type: text/vnd.ms-excel; name=\"$filename\"\n";
+ $message .= "Content-Disposition: inline; filename=\"$filename\"\n\n";
+ $message .= $attachment;
+ $message .= "\n\n--$mimeSeparator\n";
+
+ if (mail ($to, $subject, $message, $headers) == false) {
+ return "ERROR: Unable to send email to $to
";
+ } else {
+ return "Email sent to $toDisplay
";
+ } // if
+} // mailReport
+?>