[Asterisk-cvs] astcc astcc-admin.cgi,1.7,1.8

markster at lists.digium.com markster at lists.digium.com
Sat Sep 18 09:55:16 CDT 2004


Update of /usr/cvsroot/astcc
In directory mongoose.digium.com:/tmp/cvs-serv13123

Modified Files:
	astcc-admin.cgi 
Log Message:
Merge darren's e-mail info and list patch ()bug #2375)


Index: astcc-admin.cgi
===================================================================
RCS file: /usr/cvsroot/astcc/astcc-admin.cgi,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- astcc-admin.cgi	1 Sep 2004 18:33:35 -0000	1.7
+++ astcc-admin.cgi	18 Sep 2004 13:59:16 -0000	1.8
@@ -119,6 +119,19 @@
 	return "";
 }
 
+sub list_cards() {
+	my $sth;
+	my @cardlist;
+	my $row;
+	$sth = $dbh->prepare("SELECT number FROM cards");
+	$sth->execute;
+	while($row = $sth->fetchrow_hashref) {
+		push @cardlist, $row->{number};
+	}
+	$sth->finish;
+	return @cardlist;
+}
+
 sub list_trunks() {
 	my $sth;
 	my @trunklist;
@@ -160,8 +173,17 @@
 sub findunique() {
 	my $number;
 	for (;;) {
-		$number = int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000); # . int(rand() * 9000 + 1000);
+		$number = int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000) . int(rand() * 9000 + 1000);
+		if ($config{'startingdigit'} ne "" ) {
+			$startingdigit = substr($number, 0, 1);	
+			if ($startingdigit == $config{'startingdigit'}) {
+				$number = substr($number, 0, $config{'cardlength'});			
+				return $number if (&isunique($number));
+			}
+		} else	{
+		$number = substr($number, 0, $config{'cardlength'});
 		return $number if (&isunique($number));
+		}
 	}
 }
 
@@ -183,6 +205,11 @@
 	# Retrieve brand specifications
 	my $sth = $dbh->prepare("SELECT * FROM brands WHERE name = " . $dbh->quote($brand));
 	$sth->execute;
+	if ($config{'email'} eq "YES") {
+		open (EMAIL, "| $config{mailprog} $config{emailadd} -s 'New Cards Created'") ||
+			die "Error - could not write to $config{mailprog}\n";
+		print EMAIL "You have added $count $brand cards in the amount of $pennies cents. \n\n"; 
+	}
 	if ($row = $sth->fetchrow_hashref) {
 		($language, $inc, $markup) = ($row->{language}, $row->{inc}, $row->{markup});
 	}
@@ -191,8 +218,15 @@
 	for ($x=0; $x < $count; $x++) {
 		$number = &findunique;
 		&addcard($number, $language, $pennies * 100, $inc, $markup);
+		if ($config{'email'} eq "YES") {
+			print EMAIL "$number \n";
+		}
 		$status .= "$number<br>";
 	}
+	if ($config{'email'} eq "YES") {
+		print EMAIL ".\n";
+		close (EMAIL);
+	}
 	return $status;
 }
 
@@ -223,6 +257,21 @@
 		} else {
 			$status = &generatecards($count, $pennies, $brand);
 		}
+	} elsif (param('action') eq "Drop...") {
+		if ($dbh->do("DELETE FROM cards WHERE number = " . $dbh->quote(param('number')))) {
+			$status = "Dropped card " . param('number') . "'.";
+		} else {
+ 			$status = "Unable to drop card ". param('number') . "'.";
+		}
+	} elsif (param('action') eq "Refill...") {
+		$cardinfo = &getcard(param('refillnum'));
+		$number = $cardinfo->{number};
+		$newfacevalue = $cardinfo->{facevalue} + (param('refillpennies') * 100);
+		if ($dbh->do("UPDATE cards SET facevalue= $newfacevalue WHERE number= $cardinfo->{number}")) { 
+			$status = "Refilled card " . param('refillnum') . "'.";
+		} else {
+ 			$status = "Unable to Refill card". param('refillnum') . "'.";
+		}
 	} 
 	$total = &count_cards();
 	$used = &count_cards("WHERE firstuse > 0");
@@ -232,10 +281,20 @@
 		textfield(-name => "count", -size => 8) . "&nbsp;" . $brands . "&nbsp;&nbsp;cards of&nbsp;&nbsp;" .
 		textfield(-name => "pennies", -size => 8) . "&nbsp;&nbsp;pennies&nbsp;&nbsp;" .
 		submit(-name => "action", -value => "Generate...") . "</td></tr>";
+	$body .= "<tr><td>Add Money to Card&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
+		textfield(-name => "refillnum", -size => 20) . "&nbsp;&nbsp;In the Amount of &nbsp;&nbsp;" .
+		textfield(-name => "refillpennies", -size => 8) . "&nbsp;&nbsp;pennies&nbsp;&nbsp;" .
+		submit(-name => "action", -value => "Refill...") . "</td></tr>";	
 	$body .= "<tr><td>Get information on card&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
-		textfield(-name => "cardnum", -size => 15)  . "&nbsp;&nbsp;&nbsp;&nbsp;" .
+		textfield(-name => "cardnum", -size => 20)  . "&nbsp;&nbsp;&nbsp;&nbsp;" .
 		submit(-name => "action", -value => "Information...") . "</td></tr>";
+	$body .= "<tr><td>Delete card&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
+		textfield(-name => "number", -size => 20)  . "&nbsp;&nbsp;&nbsp;&nbsp;" .
+		submit(-name => "action", -value => "Drop...") . "</td></tr>";	
+	$body .= "<tr><td>List Cards&nbsp;&nbsp;" . hidden(-name => "mode", -value => "Cards") .
+		submit(-name => "action", -value => "List_Cards...") . "</td></tr>";
 	$body .= "</table>";
+	$cardnum = param('cardnum');
 	if ((param('action') eq "Information...") && length(param('cardnum'))) {
 		my $cardinfo;
 		my $status;
@@ -270,7 +329,30 @@
 			}
 		}
 		$body .= "</table>";
-	}
+	} elsif (param('action') eq "List_Cards...") {
+		my $cardinfo;
+		my $status;
+		@cardlist = &list_cards();
+		$body .= "<table>";
+		$body .= "<tr bgcolor=ffffff><tdcolspan=4><i>" . $status . "</i></td></tr>\n";
+		$body .= "<tr bgcolor=ccccff><td>Card Number</td><td>Amount Used</td><td>Face Value</td><td>Markup</td><td>Creation</td><td>First Use</td><td>Expiration</td><td>In Use</td></tr>\n";
+		foreach (@cardlist) {
+			$cardnum = $_;
+			$cardinfo = &getcard($cardnum);
+			if ($cardinfo->{'number'}) {
+				$count++;
+					if (!($count % 2)) {
+					$color = "#ccffcc";
+				} else {
+					$color = "#ffffcc";
+				}
+
+			$body .= "<tr bgcolor=$color><td>$cardnum</td><td>$cardinfo->{used}</td><td>$cardinfo->{facevalue}</td><td>$cardinfo->{markup}</td><td>$cardinfo->{creation}</td><td>$cardinfo->{firstuse}</td><td>$cardinfo->{expiration}</td><td>$cardinfo->{inuse}"; 
+			$body .= "</td></tr>\n";
+			}
+		}
+		$body .= "</table>";
+	} 
 	return $body;
 }
 
@@ -433,8 +515,6 @@
 		} elsif (param("action$x") eq "Save...") {
 			if ($dbh->do("UPDATE trunks SET name=" . $dbh->quote(param("newname$x")) .
 				" WHERE name=" . $dbh->quote(param("item$x")))) {
-#				$dbh->do("UPDATE routes SET name=" . $dbh->quote(param("newname$x")) .
-#				" WHERE name=" . $dbh->quote(param("item$x")));
 				$tmp = "REPLACE INTO trunks (name,tech,path) VALUES (" .
 					$dbh->quote(param("newname$x")) . ", " . $dbh->quote(param("newtech$x")) .
 					", " . $dbh->quote(param("newpath$x")) . ")";
@@ -684,6 +764,11 @@
 		$config{dbpass} = param('dbpass');
 		$config{dbname} = param('dbname');
 		$config{dbhost} = param('dbhost');
+		$config{cardlength} = param('cardlength');		
+		$config{startingdigit} = param('startingdigit');			
+		$config{email} = param('email');
+		$config{emailadd} = param('emailadd');
+		$config{mailprog} = param('mailprog');
 		&save_config();
 		$activity = "Configuration saved...";
 		if ($action eq "Create Database") {
@@ -702,6 +787,12 @@
 	$body .= "<tr><td>Username</td><td>" . textfield(-name => 'dbuser', -default => $config{dbuser}) . "</td></tr>";
 	$body .= "<tr><td>Password</td><td>" . textfield(-name => 'dbpass', -default => $config{dbpass}) . "</td></tr>";
 	$body .= "<tr><td>Database</td><td>" . textfield(-name => 'dbname', -default => $config{dbname}) . "</td></tr>";
+	$body .= "<tr><td>Card Length (4-20) </td><td>" . textfield(-name => 'cardlength', -default => $config{cardlength}) . "</td></tr>";	
+	$body .= "<tr><td>Card Starting Number - </td></tr>";
+	$body .= "<tr><td>Enter 0 if Not Required </td><td>" . textfield(-name => 'startingdigit', -default => $config{startingdigit}) . "</td></tr>";
+	$body .= "<tr><td>Email New Card Info (YES/NO) </td><td>" . textfield(-name => 'email', -default => $config{email}) . "</td></tr>";
+	$body .= "<tr><td>Admin Email</td><td>" . textfield(-name => 'emailadd', -default => $config{emailadd}) . "</td></tr>";
+	$body .= "<tr><td>Email Program</td><td>" . textfield(-name => 'mailprog', -default => $config{mailprog}) . "</td></tr>";
 	$body .= "<tr><td align=left>&nbsp;" . submit(-name => 'action', -value => 'Save') . "</td><td align=right>" . submit( -name => 'action', -value => 'Create Database') . "&nbsp;</td></tr>";
 	$body .= "</table>";
 	return $body;




More information about the svn-commits mailing list