function validate_generate_form() { global $db, $t, $vars; $error = array(); if ($vars['count'] <= 0) { $error[] = 'Please enter numeric Coupons Count'; } if ($vars['use_count'] <= 0) { $error[] = 'Please enter numeric Coupon Usage Count'; } if ($vars['member_use_count'] <= 0) { $error[] = 'Please enter numeric Member Coupon Usage Count'; } if ($vars['code_len'] <= 0) { $error[] = 'Please enter numeric Code Length'; } if ($vars['code_len'] > 32) { $error[] = 'Please enter numeric Code Length less or equal 32'; } if ($vars['discount_v'] <= 0) { $error[] = 'Please enter numeric discount value'; } if ($error) { $t->assign('error', $error); display_generate_form(); return 0; } return 1; }
function generate_attendance($title) { if (!check('CR')) { header('location:./?sub'); } else { if (!check_day()) { $p = $_SERVER['QUERY_STRING']; $reg = '/^P[1-4]$/'; if (preg_match($reg, $p)) { include 'config/db.php'; include 'config/settings.php'; include 'config/globals.php'; $dbname = $branchyear . '_Users'; $table = $branchyear . '_Students'; //if(!mysql_select_db($dbname)) die(mysql_error()); $userid = $_SESSION['UserId']; $q = "select Branch,Class from {$table} where Id = '{$userid}'"; $res = mysql_query($q) or die(mysql_error()); $row = mysql_fetch_array($res); $branch = $row['Branch']; $class = $row['Class']; echo "<!DOCTYPE html>\n<html>\n"; display_headers($title); echo "\n<body>"; menu(); echo <<<a \t\t\t \t<div class="container" style="margin-top:-10px;"><br> \t\t\t a; $dbname = $branchyear . '_Attendance'; $table = $branch . $class . '_Attendance'; //if(!mysql_select_db($dbname)) die(mysql_error()); $class_total = mysql_num_rows(mysql_query("select `Id` from {$table}")); $sample = mt_rand(1, $class_total); $da = date('d-m-Y'); $date = date('d-m-Y'); $dbname = $branchyear . '_Dates'; $table = $branch . $class . '_Dates'; //if(!mysql_select_db($dbname)) die(mysql_error()); $q = mysql_query("select Date from {$table} where Date = '{$da}'") or die(mysql_error()); if (mysql_num_rows($q) == 0) { $q = mysql_query("insert into {$table}(Date) values('{$da}')") or die(mysql_error()); $dbname = $branchyear . '_Cache'; $table = $branch . $class . '_Cache'; //if(!mysql_select_db($dbname)) die(mysql_error()); for ($j = 1; $j <= 4; $j++) { $q = mysql_query("alter table {$table} add `" . $da . "_P" . $j . "` varchar(2);") or die(mysql_error()); } insert_log($_SESSION['UserId'] . " added {$date} Cache columns to {$table}"); $dbname = $branchyear . '_Attendance'; $table = $branch . $class . '_Attendance'; //if(!mysql_select_db($dbname)) die(mysql_error()); $q = mysql_query("alter table {$table} add `" . $da . "` varchar(30) default '';") or die(mysql_error()); insert_log($_SESSION['UserId'] . "added {$date} to Attendance columns to {$table}"); } echo <<<a \t\t\t<div id="error" style="display:none;margin-top:10px;"></div> \t\t\t \t\t<div class="row"> \t\t\t\t<div class='span9'> \t\t\t\t\t<div class="well well-large" style="background:#FFF;"> a; $dbname = $branchyear . '_Dates'; $table = $branch . $class . '_Dates'; //if(!mysql_select_db($dbname)) die(mysql_error()); $q = mysql_query("select {$p},`" . $p . "_Con` from {$table} where Date = '{$da}';") or die(mysql_error()); $row = mysql_fetch_array($q); $a = $da . '_' . $p; if (isset($_POST['Generate'])) { if ($row[$p] == 'ok') { echo "<script>show_error('{$p} Attendance has been already uploaded ');</script>"; } else { $key2 = addslashes($_POST['Skey']); $table = $branchyear . '_CRs'; $q = "select `Id`,`Key` from {$table} where `Id` = '{$userid}'"; $res = mysql_query($q) or die(mysql_error()); $row = mysql_fetch_array($res); $key1 = $row['Key']; if ($key1 != $key2) { echo "<script>show_error('<b>Error </b> : CR Security Key does not matched. Please try again.. ');</script>"; } else { $dbname = $branchyear . '_Cache'; $table = $branch . $class . '_Cache'; //if(!mysql_select_db($dbname))die(mysql_error()); $less = addslashes($_POST['Less']); $rnos = addslashes($_POST['RNos']); $lastone = $rnos[strlen($rnos) - 1]; $rollno[$less] = $lastone != ',' ? explode(',', $rnos) : explode(',', $rnos, -1); if ($less == "Absents") { for ($i = 1, $c = 0; $i <= $class_total; $i++) { if (!in_array($i, $rollno["Absents"])) { $rollno["Presents"][$c++] = $i; } } } else { for ($i = 1, $c = 0; $i <= $class_total; $i++) { if (!in_array($i, $rollno["Presents"])) { $rollno["Absents"][$c++] = $i; } } } if (array_key_exists('Absents', $rollno)) { foreach ($rollno['Absents'] as $val) { $insert = mysql_query("UPDATE " . $table . " SET `{$a}` = 'A' WHERE RNo ='{$val}';") or die(mysql_error()); } } if (array_key_exists('Presents', $rollno)) { foreach ($rollno['Presents'] as $val) { $insert = mysql_query("UPDATE " . $table . " SET `{$a}` = 'P' WHERE RNo ='{$val}';") or die(mysql_error()); } } $dbname = $branchyear . '_Dates'; $table = $branch . $class . '_Dates'; //if(!mysql_select_db($dbname)) die(mysql_error()); $in = mysql_query("UPDATE " . $table . " SET `{$p}` = 'ok' WHERE Date ='{$da}';") or die(mysql_error()); echo "<script>show_success('{$p} Attendance has been uploaded ');</script>"; } } } $dbname = $branchyear . '_Dates'; $table = $branch . $class . '_Dates'; //if(!mysql_select_db($dbname)) die(mysql_error()); $remaining = array(); $j = 0; $remaining1 = array(); $j1 = 0; $confired = array(); $j2 = 0; $confired1 = array(); $j3 = 0; for ($i = 1; $i <= 4; $i++) { $tmp = "P" . $i; $tmp1 = "P" . $i . "_Con"; $q = mysql_query("select ISNUll(`{$tmp}`) as `P{$i}`,ISNUll(`{$tmp1}`) as `P" . $i . "_C` from {$table} where Date = '{$da}' ") or die(mysql_error()); $res = mysql_fetch_array($q); if ($res["P" . $i]) { $remaining[$j] = "P" . $i; $j++; } else { $remaining1[$j1] = "P" . $i; $j1++; } if ($res["P" . $i . "_C"]) { $confired[$j2] = "P" . $i; $j2++; } else { $confired1[$j3] = "P" . $i; $j3++; } } $dates1 = getdate(strtotime($da)); $day = substr($dates1["weekday"], 0, 3); $dbname = $branchyear . '_TimeTable'; $table = $branch . $class . '_TimeTable'; //if(!mysql_select_db($dbname)) die(mysql_error()); $ti = mysql_query("SELECT DayPeriod,{$day} from {$table};") or die(mysql_error()); $subjects = array(); while ($da = mysql_fetch_array($ti)) { $subjects[$da[0]] = $da[1]; } $sub = $subjects[$p]; if (in_array($p, $remaining1)) { echo "<h5 style='text-align:center;'> Attendance Submission Details - {$branch} {$class}</h5><br>"; //$p="P".$m; if (in_array($p, $confired1)) { $period = $p; $dbname = $branchyear . '_Attendance'; $table = $branch . $class . '_Attendance'; //if(!mysql_select_db($dbname)) die(mysql_error()); $q = mysql_query("select RNo,Id,`{$date}` from {$table};") or die(mysql_error()); $Rnos = array("Absents" => array(), "Presents" => array()); $aindex = 0; $pindex = 0; $uid = array(); while ($res = mysql_fetch_array($q)) { $uid[$res['RNo']] = $res['Id']; $z = explode(",", $res[$date]); for ($m = 0; $m < count($z); $m++) { $y = explode("_", $z[$m]); if ($y[0] == $period) { if ($y[1] == "A") { $Rnos['Absents'][$aindex] = $res[0]; $aindex++; } else { $Rnos['Presents'][$pindex] = $res[0]; $pindex++; } } } } } else { $da = date('d-m-Y'); $a = $da . '_' . $p; $dbname = $branchyear . '_Cache'; $table = $branch . $class . '_Cache'; //if(!mysql_select_db($dbname)) die(mysql_error()); $q3 = mysql_query("SELECT RNo, `" . $a . "` FROM {$table}") or die(mysql_error()); $Rnos = array("Absents" => array(), "Presents" => array()); $aindex = 0; $pindex = 0; while ($individual = mysql_fetch_array($q3)) { if ($individual[$a] == "A") { $Rnos["Absents"][$aindex] = $individual["RNo"]; $aindex++; } if ($individual[$a] == "P") { $Rnos["Presents"][$pindex] = $individual["RNo"]; $pindex++; } } } $pc = count($Rnos["Presents"]); $ac = count($Rnos["Absents"]); $tot = $pc + $ac; //print_r($Rnos); //print_r($uid); echo <<<tab \t\t\t\t \t\t\t\t<div class="row"> \t\t\t\t\t<div class="span8"> \t\t\t\t\t<table class="table table-hover table-bordered" > \t\t\t\t\t\t<tbody> \t\t\t\t\t\t\t<tr> <td class="span2" style="text-align:center"> Date </td> <th class="text-warning span2" style="text-align:center"> {$date}</th> \t\t\t\t\t\t\t<td class="span2" style="text-align:center"> Subject </td> <th class="text-success span2" style="text-align:center"> {$sub}</th> </tr> \t\t\t\t\t\t</tbody> \t\t\t\t\t</table> \t\t\t\t\t</div> \t\t\t\t</div> <div class="row"> \t<div class="span8"> <table class="table table-hover table-bordered" > <thead> <tr> <th class="span2" style="text-align:center"> Period # </th> <th class="span3"> Presents </th> <th class="span3"> Absents </th> </tr> </thead> <tbody> <tr><td style="text-align:center;" >{$p}</td><td> tab; for ($i = 0; $i < $pc; $i++) { if ($i % 8 == 0 && $i != 0) { echo "<br>"; } if ($i == $pc - 1) { echo $Rnos["Presents"][$i]; } else { echo $Rnos["Presents"][$i] . ","; } } echo "</td><td>"; for ($i = 0; $i < $ac; $i++) { if ($i % 8 == 0 && $i != 0) { echo "<br>"; } if ($i == $ac - 1) { echo $Rnos["Absents"][$i]; } else { echo $Rnos["Absents"][$i] . ","; } } echo <<<tab \t\t\t\t\t\t</td></tr> \t\t\t\t\t\t<tr> \t\t\t\t\t\t\t<td style="text-align:center;" >Total (<b>{$class_total}</b>) </td> \t\t\t\t\t\t\t<td style="text-align:center;" class='text-success'> {$pc}</td> \t\t\t\t\t\t\t<td style="text-align:center;" class='text-error'>{$ac}</td> \t\t\t\t\t\t\t</tr> \t\t\t\t\t\t</tbody> \t\t\t\t\t</table> \t\t\t\t\t</div> \t\t\t\t</div> tab; } else { display_generate_form($p, $class_total, $sub, $branch . $class); } echo <<<a \t\t\t\t\t</div> \t\t\t\t</div> \t\t\t\t<div class='span3'> a; go_home(); echo '<ul class="nav nav-tabs nav-stacked">'; for ($i = 1; $i <= 4; $i++) { echo "<li><a href=\"?P{$i}\">P{$i}"; $period = "P" . $i; if (!in_array($period, $remaining)) { echo "<i class='icon-ok pull-right text-success' style=\"padding-top:5px;\"></i>"; } else { echo "<i class='icon-remove pull-right text-error' style='padding-top:5px;'></i>"; } echo '<i class="icon-chevron-right pull-left" style="padding-top:5px;"></i></a> </li>'; } echo "</ul></div>"; echo "</div> </div> "; display_footer(); echo "\n</body>\n</html>"; @mysql_close($con); } else { echo "<script type='text/javascript'>document.location.href='404.php';</script>"; } } else { noservice(); } } }