示例#1
0
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}&nbsp;{$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();
        }
    }
}
示例#2
0
function generate_attendance($title)
{
    if (!check_login()) {
        header('location:./login.php');
    } else {
        if (!check_day()) {
            include 'config/globals.php';
            $p = $_SERVER['QUERY_STRING'];
            $reg = "/^" . $globalbranch . "[1-" . $classno . "]{1}\$/";
            if (preg_match($reg, $p)) {
                include 'config/db.php';
                include 'config/settings.php';
                include 'config/globals.php';
                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<div id="error" style="display:none;margin-top:10px;"></div>
\t\t\t
a;
                $table = '';
                //$spread='';
                $dbname = $branchyear . '_Users';
                $table = $branchyear . '_Students';
                //if(!mysql_select_db($dbname)) die(mysql_error());
                $userid = $_SESSION['UserId'];
                $q = "select Branch,Class,Position from {$table} where Id = '{$userid}'";
                $res = mysql_query($q) or die(mysql_error());
                $row = mysql_fetch_array($res);
                if ($row['Position'] == "BA") {
                    $branch = $globalbranch;
                    $class = substr($p, -1);
                } else {
                    $branch = $row['Branch'];
                    $class = $row['Class'];
                    $class1 = substr($p, -1);
                    if ($class1 != $class) {
                        //echo 'i am in';
                        echo "<script type='text/javascript'>show_error('Error: Not authorised to access {$branch}{$class1} details.');</script>";
                    }
                }
                echo <<<a
\t\t\t
\t\t\t
\t\t<div class="row">
\t\t\t\t<div class='span12'>
\t\t\t\t\t<div class="well well-large" style="background:#FFF;">
a;
                echo <<<a
\t\t\t
\t\t\t\t<div id="step1" class="span4">     
\t\t\t\t\t<h5 class='text-info'>Time Table Details for Class {$branch}&nbsp;{$class} </h5>
\t\t\t\t\t<h6> &emsp;&emsp;&emsp; - &emsp; Listing Data present in our database </h6><br>
\t\t\t\t</div>
\t\t\t\t<div id="side1" class="span7" >
\t\t\t\t\t<h6 class='text-right'><a href='./?sub'><i class='icon-home'></i> Home&nbsp;</a> </h6>
a;
                if ($row['Position'] == "BA") {
                    echo <<<a
\t\t\t\t\t<h6 class='text-right'>
a;
                    for ($cl = 1; $cl <= $classno; $cl++) {
                        echo "<a href='?{$globalbranch}{$cl}'>{$globalbranch}{$cl}</a>&emsp;";
                    }
                    echo <<<a
\t\t\t\t\t</h6>
a;
                }
                echo <<<a
\t\t\t\t</div>
\t\t\t
a;
                $html = "";
                echo '<table class="table  table-hover table-bordered "  style="padding:0px;">
						<thead>
							<tr> 
								<th style="text-align:center;"  > Period/Day  </th> 
								<th style="text-align:center;"  > Monday  </th> 
								<th style="text-align:center;"  > Tuesday  </th> 
								<th style="text-align:center;"  > Wednesday  </th> 
								<th style="text-align:center;"  > Thursday  </th> 
								<th style="text-align:center;"  > Friday  </th> 
								<th style="text-align:center;"  > Saturday  </th> 
							</tr>
						</thead>
						<tbody>';
                //$spread.=" \t \t P1  \t P2 \t  P3 \t P4 \t \t \t\nRno\tID\t".$subjects['P1']."\t".$subjects['P2']."\t".$subjects['P3']."\t".$subjects['P4']."\tPresents\tAbsents\n";
                $html .= "<thead><tr> \n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t<th > Period/Day </th> \n\t\t\t\t\t\t\t\t<th > Monday </th>\n\t\t\t\t\t\t\t\t<th > Tuesday </th>  \n\t\t\t\t\t\t\t\t<th > Wednesday </th>\n\t\t\t\t\t\t\t\t<th > Thursday </th>\n\t\t\t\t\t\t\t\t<th > Friday </th>  \n\t\t\t\t\t\t\t\t<th > Saturday </th> \n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t</thead><tbody>";
                $dbname = $branchyear . '_TimeTable';
                $table = $branch . $class . '_TimeTable';
                //if(!mysql_select_db($dbname)) die(mysql_error());
                $ti = mysql_query("SELECT * from {$table};") or die(mysql_error());
                while ($res = mysql_fetch_array($ti)) {
                    echo "<tr>";
                    $html .= "<tr>";
                    for ($ct = 0; $ct < 7; $ct++) {
                        if ($ct == 0) {
                            echo "<th><center>" . $res[$ct] . "</center></th>";
                            $html .= "<th><center>" . $res[$ct] . "</center></th>";
                        } else {
                            echo "<td><center>" . $res[$ct] . "</center></td>";
                            $html .= "<td><center>" . $res[$ct] . "</center></td>";
                        }
                    }
                    $html .= "</tr>";
                    echo "</tr>";
                }
                $html .= "</tbody></table><br><br><table style=\"border-collapse:collapse;width:100%;margin-left:0%;font-size:12px;\" border=1 ><tr>\n\t\t\t<th width=25% ><center>Short Name</center></th><th> Long Name</th></tr>";
                echo "</tbody></table>";
                echo <<<a
\t\t\t<br>
\t\t\t<table class='table  table-hover table-bordered' >
\t\t<tr>
\t\t\t<th width=25% ><center>Short Name</center></th><th> Long Name</th>
\t\t</tr>
\t\t
a;
                foreach ($sub_def as $key => $val) {
                    echo "<tr><th><center>{$key}</center></th><td>{$val}</td></tr>";
                    $html .= "<tr><th><center>{$key}</center></th><td>&emsp;{$val}</td></tr>";
                }
                echo <<<a
\t\t</table>\t
a;
                if ($row['Position'] == "BA") {
                    echo <<<a
\t\t\t<form action='print.php' method='post' name='abc'>
\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Time Table Report">
\t\t\t<input type='hidden' name='Table1' value='{$html}'>
\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as PDF</button></center>
\t\t\t</form>
a;
                    echo <<<b
\t\t\t<form action='excel.php' method='post' name='abc'>
\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Time Table Report">
\t\t\t<input type='hidden' name="sheet" value='{$html}'>
\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as Excel Sheet</button></center>
\t\t\t</form>
b;
                }
                echo <<<a
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t
a;
                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();
        }
    }
}
示例#3
0
function generate_attendance($title)
{
    if (!check_login()) {
        header('location:./login.php');
    } else {
        if (!check_day()) {
            include 'config/globals.php';
            $p = $_SERVER['QUERY_STRING'];
            $reg = "/^" . $globalbranch . "[1-" . $classno . "]{1}\$/";
            if (preg_match($reg, $p)) {
                include 'config/db.php';
                include 'config/settings.php';
                include 'config/globals.php';
                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<div id="error" style="display:none;margin-top:10px;"></div>
\t\t\t
a;
                $table = '';
                //$spread='';
                $dbname = $branchyear . '_Users';
                $table = $branchyear . '_Students';
                //if(!mysql_select_db($dbname)) die(mysql_error());
                $userid = $_SESSION['UserId'];
                $q = "select Branch,Class,Position from {$table} where Id = '{$userid}'";
                $res = mysql_query($q) or die(mysql_error());
                $row = mysql_fetch_array($res);
                if ($row['Position'] == "BA") {
                    $branch = $globalbranch;
                    $class = substr($p, -1);
                } else {
                    $branch = $row['Branch'];
                    $class = $row['Class'];
                    $class1 = substr($p, -1);
                    if ($class1 != $class) {
                        //echo 'i am in';
                        echo "<script type='text/javascript'>show_error('Error: Not authorised to access {$branch}{$class1} details.');</script>";
                    }
                }
                $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');
                echo <<<a
\t\t\t
\t\t\t
\t\t<div class="row">
\t\t\t\t<div class='span12'>
\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());
                $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 ($da1 = mysql_fetch_array($ti)) {
                    $subjects[$da1[0]] = $da1[1];
                }
                //print_r($subjects);
                //$sub = $subjects[$p];
                //echo "<h5 style='text-align:center;'> Attendance Submission Details - $branch&nbsp;$class - $date</h5><br>";
                echo <<<a
\t\t\t
\t\t\t\t<div id="step1" class="span4">     
\t\t\t\t\t<h5 class='text-info'>Today's Attendance Submission Details </h5>
\t\t\t\t\t<h6> &emsp;&emsp;&emsp; - &emsp; Listing Data submitted from CR @ {$branch}&nbsp;{$class} </h6><br>
\t\t\t\t</div>
\t\t\t\t<div id="side1" class="span7" >
\t\t\t\t\t<h6 class='text-right'><a href='./?sub'><i class='icon-home'></i> Home&nbsp;</a> </h6>
a;
                if ($row['Position'] == "BA") {
                    echo <<<a
\t\t\t\t\t<h6 class='text-right'>
a;
                    for ($cl = 1; $cl <= $classno; $cl++) {
                        echo "<a href='?{$globalbranch}{$cl}'>{$globalbranch}{$cl}</a>&emsp;";
                    }
                    echo <<<a
\t\t\t\t\t</h6>
a;
                }
                echo <<<a
\t\t\t\t</div>
\t\t\t
a;
                $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 (count($remaining1) != 0 && mysql_num_rows($q) != 0) {
                    $html = "";
                    echo '<table class="table  table-hover table-bordered "  style="padding:0px;">
						<thead>
							<tr> 
								<th style="text-align:center;"  rowspan="2" valign="top"> RNo  </th> 
								<th style="text-align:center;"  rowspan="2" valign="top"> Id  </th> 
								<th  style="text-align:center;"  > P1 </th> <th  style="text-align:center;" > P2 </th>
								<th  style="text-align:center;"  > P3 </th>  <th  style="text-align:center;"  > P4 </th> 
								<th  style="text-align:center;" rowspan=2> Presents </th> <th rowspan=2 style="text-align:center;"  > Absents </th>
							</tr>
							<tr> 
								<th  style="text-align:center;"  > ' . $subjects['P1'] . ' </th> <th  style="text-align:center;" > ' . $subjects['P2'] . ' </th>
								<th  style="text-align:center;"  > ' . $subjects['P3'] . ' </th>  <th  style="text-align:center;"  > ' . $subjects['P4'] . ' </th> 
								
							</tr>
							
						</thead>
						<tbody>';
                    //$spread.=" \t \t P1  \t P2 \t  P3 \t P4 \t \t \t\nRno\tID\t".$subjects['P1']."\t".$subjects['P2']."\t".$subjects['P3']."\t".$subjects['P4']."\tPresents\tAbsents\n";
                    $html .= "<thead><tr> \n\t\t\t\t\t\t\t\t<th rowspan=\"2\" width=8%> RNo  </th> \n\t\t\t\t\t\t\t\t<th rowspan=\"2\" width=17%> ID  </th> \n\t\t\t\t\t\t\t\t<th  > P1 </th> <th > P2 </th>\n\t\t\t\t\t\t\t\t<th  > P3 </th>  <th  > P4 </th> \n\t\t\t\t\t\t\t\t<th rowspan=2 width=14%> Presents </th> <th rowspan=2  width=14%> Absents </th>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr> \n\t\t\t\t\t\t\t\t<th  > {$subjects['P1']}</th> <th >{$subjects['P2']}</th>\n\t\t\t\t\t\t\t\t<th  > {$subjects['P3']} </th>  <th  > {$subjects['P4']} </th> \n\t\t\t\t\t\t\t</tr></thead>";
                    $Rnos = array();
                    $uid = array();
                    $dbname = $branchyear . '_Attendance';
                    $table = $branch . $class . '_Attendance';
                    //if(!mysql_select_db($dbname)) die(mysql_error());
                    $q = mysql_query("select Id, RNo from {$table};") or die(mysql_error());
                    while ($res = mysql_fetch_array($q)) {
                        $uid[$res['RNo']] = $res['Id'];
                    }
                    for ($s = 0; $s < count($remaining1); $s++) {
                        $p1 = $remaining1[$s];
                        if (in_array($p1, $confired1)) {
                            $period = $p1;
                            $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());
                            $aindex = 0;
                            $pindex = 0;
                            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[$p1]['Absents'][$aindex] = $res[0];
                                            $aindex++;
                                        } else {
                                            $Rnos[$p1]['Presents'][$pindex] = $res[0];
                                            $pindex++;
                                        }
                                    }
                                }
                            }
                        } else {
                            $da = date('d-m-Y');
                            $a = $da . '_' . $p1;
                            $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());
                            $aindex = 0;
                            $pindex = 0;
                            while ($individual = mysql_fetch_array($q3)) {
                                if ($individual[$a] == "A") {
                                    $Rnos[$p1]["Absents"][$aindex] = $individual["RNo"];
                                    $aindex++;
                                }
                                if ($individual[$a] == "P") {
                                    $Rnos[$p1]["Presents"][$pindex] = $individual["RNo"];
                                    $pindex++;
                                }
                            }
                        }
                    }
                    $tot = array('A' => 0, 'P' => 0);
                    //print_r($uid);
                    for ($w = 1; $w <= $class_total; $w++) {
                        $tr2 = '<tr >  
						<td style="text-align:center;">' . $w . '  </td>
						<td style="text-align:center;"> ' . $uid[$w] . '  </td>';
                        echo $tr2;
                        //$spread.="$w \t {$uid[$w]} \t";
                        $html .= $tr2;
                        $pc = 0;
                        $ac = 0;
                        for ($l = 1; $l <= 4; $l++) {
                            $pl = "P" . $l;
                            if (in_array($pl, $remaining1)) {
                                if (array_key_exists("Absents", $Rnos[$pl]) && in_array($w, $Rnos[$pl]['Absents'])) {
                                    echo '<td style="text-align:center;" class="text-error"><b> <i class="icon-remove"></i> </b></td>';
                                    $ac++;
                                    $html .= "<td><font color=\"darkred\">&#x2716;</font></td>";
                                } else {
                                    echo '<td style="text-align:center;" class="text-success"><b> <i class="icon-ok"></i> </b></td>';
                                    $pc++;
                                    $html .= "<td><font color=\"green\">&#x2714;</font></td>";
                                }
                            } else {
                                echo '<td></td>';
                                $html .= '<td></td>';
                                //$spread.=" \t";
                            }
                        }
                        $tot['A'] += $ac;
                        $tot['P'] += $pc;
                        echo <<<a
\t\t\t\t\t\t<td style="text-align:center;" class="text-success"><b> {$pc} </b> </td> 
\t\t\t\t\t\t<td style="text-align:center;" class="text-error"><b> {$ac} </b></td>  
\t\t\t\t\t</tr>
\t\t\t\t\t
a;
                        $html .= "<td><font color=\"green\"><b>{$pc}</b></font></td><td><font color=\"darkred\"><b>{$ac}</b></font></td></tr>";
                        //$spread.="$pc \t $ac \n";
                    }
                    echo "<tr><td colspan=6 style='text-align:center;'><b>Total</b></td><td style='text-align:center;' class='text-success'><b>" . $tot['P'] . "</b></td><td style='text-align:center;' class='text-error'><b>" . $tot['A'] . "</b></td></tr>";
                    $html .= "<tr><th colspan=6 style=\"text-align:center;\"> <b>Total</b> </th><td><b><font color=\"green\">" . $tot['P'] . "</font></b></td><td><b><font color=\"darkred\">" . $tot['A'] . "</font></b></td></tr>";
                    //$spread.="\t \tTotal\t \t \t \t{$tot['P']} \t {$tot['A']}";
                    echo "</tbody></table>";
                    if ($row['Position'] == "BA") {
                        echo <<<a
\t\t\t<form action='print.php' method='post' name='abc'>
\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Daily Report">
\t\t\t<input type='hidden' name='Table1' value='{$html}'>
\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as PDF</button></center>
\t\t\t</form>
a;
                        echo <<<b
\t\t\t<form action='excel.php' method='post' name='abc'>
\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Daily Report">
\t\t\t<input type='hidden' name="sheet" value='{$html}'>
\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as Excel Sheet</button></center>
\t\t\t</form>
b;
                    }
                    echo <<<a
\t\t\t\t\t</div>
\t\t\t\t</div>
\t\t\t\t
a;
                } else {
                    echo "<br><h6><span class='text-error'><br><br><br>No Submissions found till now ...</span></h6><br></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();
        }
    }
}
示例#4
0
function generate_attendance($title)
{
    if (!check_login()) {
        header('location:./login.php');
    } else {
        include 'config/globals.php';
        $qs1 = $_SERVER['QUERY_STRING'];
        $reg1 = "/^[0-9]{2}-[0-9]{2}-[0-9]{4}\$/";
        $reg2 = "/^" . $globalbranch . "[1-" . $classno . "]{1}\$/";
        $qs = explode('/', $qs1);
        $len = count($qs);
        if ($len == 2 or $len == 3 && $qs[2] == "") {
            $ar = explode('-', $qs[0]);
            if (preg_match($reg1, $qs[0]) && preg_match($reg2, $qs[1])) {
                if (checkdate($ar[1], $ar[0], $ar[2])) {
                    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());
                    $p = $qs[1];
                    $userid = $_SESSION['UserId'];
                    $q = "select Branch,Class,Position from {$table} where Id = '{$userid}'";
                    $res = mysql_query($q) or die(mysql_error());
                    $row = mysql_fetch_array($res);
                    if ($row['Position'] == "BA") {
                        $branch = $globalbranch;
                        $class = substr($p, -1);
                    } else {
                        $branch = $row['Branch'];
                        $class = $row['Class'];
                        $class1 = substr($p, -1);
                        if ($class1 != $class) {
                            display_error("Error : Not allowed to access  {$class1} details");
                            die;
                        }
                    }
                    $da = $qs[0];
                    $date = $qs[0];
                    $dif = strtotime($da) - strtotime(date('d-m-Y'));
                    if ($dif > 0) {
                        display_error("Error : Not allowed to access future Attendance");
                    } else {
                        if (check_day2($da, $branch . $class)) {
                            display_error("Error : Not allowed to access Attendance of semester starting dates");
                        } else {
                            if (check_day1($da)) {
                                echo noservice();
                            } else {
                                echo "<!DOCTYPE html>\n<html>\n";
                                display_headers($title);
                                echo "\n<body>";
                                menu();
                                echo <<<a
\t\t\t\t\t\t
\t<div class="container" style="margin-top:-10px;"><br>
\t\t\t\t\t\t<div id="error" style="display:none;margin-top:10px;"></div>
\t\t\t\t\t\t
a;
                                $table = '';
                                //$spread='';
                                $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);
                                echo <<<a
\t\t\t\t\t\t
\t\t\t\t\t\t
\t\t
\t\t\t\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());
                                $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 ($da1 = mysql_fetch_array($ti)) {
                                    $subjects[$da1[0]] = $da1[1];
                                }
                                //print_r($subjects);
                                //$sub = $subjects[$p];
                                //echo "<h5 style='text-align:center;'> Attendance Submission Details - $branch&nbsp;$class - $date</h5><br>";
                                echo <<<a
\t\t\t\t\t\t
\t\t\t\t\t\t\t<div id="step1" class="span5">     
\t\t\t\t\t\t\t\t<h5 class='text-info'>Daily  Attendance Submission Details for {$date} </h5>
\t\t\t\t\t\t\t\t<h6> &emsp;&emsp;&emsp; - &emsp; Listing Data submitted from CR @ {$branch}&nbsp;{$class} </h6><br>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t<div id="side1" class="span6" >
\t\t\t\t\t\t\t\t<h6 class='text-right'><a href='./?sub'><i class='icon-home'></i> Home&nbsp;</a> </h6>
a;
                                if ($row['Position'] == "BA") {
                                    echo <<<a
\t\t\t\t\t\t\t\t<h6 class='text-right'>
a;
                                    for ($cl = 1; $cl <= $classno; $cl++) {
                                        echo "<a href='?{$date}/{$globalbranch}{$cl}'>{$globalbranch}{$cl}</a>&emsp;";
                                    }
                                    echo <<<a
\t\t\t\t\t\t\t\t</h6>
\t\t\t\t\t\t\t\t
a;
                                }
                                $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 (count($remaining1) != 0 && mysql_num_rows($q) != 0) {
                                    $table = $branch . $class . "_Dates";
                                    $q = mysql_query("select SNo from {$table} where Date = '{$date}'") or die(mysql_error());
                                    if (mysql_num_rows($q) == 0) {
                                        echo "<script>show_error('Attendance has been not yet uploaded ');</script>";
                                    }
                                    $sn = mysql_fetch_array($q) or die(mysql_error());
                                    $sn1 = $sn['SNo'] < 5 ? 0 : $sn['SNo'] - 5;
                                    echo '<ul class="nav nav-pills pull-right">
							  <li class="dropdown" style="margin-top:2px;">
							  <a href="#" class="dropdown-toggle" data-toggle="dropdown"> 
							   <i class="icon-calendar"></i> Date - ' . $date . ' &nbsp;<b class="caret"></b></a>
									<ul class="dropdown-menu">';
                                    //echo $sn1;
                                    $q = mysql_query("select Date from {$table}  order by SNo limit {$sn1},5") or die(mysql_errno());
                                    while ($res = mysql_fetch_array($q)) {
                                        $st1 = $res['Date'] == $date ? "active" : " ";
                                        echo "<li class='{$st1}'><a href='?" . $res['Date'] . "/" . $branch . $class . "'>" . $res['Date'] . "</a></li>";
                                    }
                                    echo '</ul>
							  </li>
							</ul>';
                                    echo <<<a
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t\t
\t\t\t\t\t\t\t
a;
                                    $html = "";
                                    echo '<table class="table  table-hover table-bordered "  style="padding:0px;">
									<thead>
										<tr> 
											<th style="text-align:center;"  rowspan="2" valign="top"> RNo  </th> 
											<th style="text-align:center;"  rowspan="2" valign="top"> Id  </th> 
											<th  style="text-align:center;"  > P1 </th> <th  style="text-align:center;" > P2 </th>
											<th  style="text-align:center;"  > P3 </th>  <th  style="text-align:center;"  > P4 </th> 
											<th  style="text-align:center;" rowspan=2> Presents </th> <th rowspan=2 style="text-align:center;"  > Absents </th>
										</tr>
										<tr> 
											<th  style="text-align:center;"  > ' . $subjects['P1'] . ' </th> <th  style="text-align:center;" > ' . $subjects['P2'] . ' </th>
											<th  style="text-align:center;"  > ' . $subjects['P3'] . ' </th>  <th  style="text-align:center;"  > ' . $subjects['P4'] . ' </th> 
											
										</tr>
										
									</thead>
									<tbody>';
                                    //$spread.=" \t \t P1  \t P2 \t  P3 \t P4 \t \t \t\nRno\tID\t".$subjects['P1']."\t".$subjects['P2']."\t".$subjects['P3']."\t".$subjects['P4']."\tPresents\tAbsents\n";
                                    $html .= "<thead><tr> \n\t\t\t\t\t\t\t\t\t\t\t<th rowspan=\"2\" width=8%> RNo  </th> \n\t\t\t\t\t\t\t\t\t\t\t<th rowspan=\"2\" width=17%> ID  </th> \n\t\t\t\t\t\t\t\t\t\t\t<th  > P1 </th> <th > P2 </th>\n\t\t\t\t\t\t\t\t\t\t\t<th  > P3 </th>  <th  > P4 </th> \n\t\t\t\t\t\t\t\t\t\t\t<th rowspan=2 width=14%> Presents </th> <th rowspan=2  width=14%> Absents </th>\n\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t<tr> \n\t\t\t\t\t\t\t\t\t\t\t<th  > {$subjects['P1']}</th> <th >{$subjects['P2']}</th>\n\t\t\t\t\t\t\t\t\t\t\t<th  > {$subjects['P3']} </th>  <th  > {$subjects['P4']} </th> \n\t\t\t\t\t\t\t\t\t\t</tr></thead>";
                                    $Rnos = array();
                                    $uid = array();
                                    $dbname = $branchyear . '_Attendance';
                                    $table = $branch . $class . '_Attendance';
                                    //if(!mysql_select_db($dbname)) die(mysql_error());
                                    $q = mysql_query("select Id, RNo from {$table};") or die(mysql_error());
                                    while ($res = mysql_fetch_array($q)) {
                                        $uid[$res['RNo']] = $res['Id'];
                                    }
                                    for ($s = 0; $s < count($remaining1); $s++) {
                                        $p1 = $remaining1[$s];
                                        if (in_array($p1, $confired1)) {
                                            $period = $p1;
                                            $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());
                                            $aindex = 0;
                                            $pindex = 0;
                                            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[$p1]['Absents'][$aindex] = $res[0];
                                                            $aindex++;
                                                        } else {
                                                            $Rnos[$p1]['Presents'][$pindex] = $res[0];
                                                            $pindex++;
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            //$da = date('d-m-Y');
                                            $a = $da . '_' . $p1;
                                            $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());
                                            $aindex = 0;
                                            $pindex = 0;
                                            while ($individual = mysql_fetch_array($q3)) {
                                                if ($individual[$a] == "A") {
                                                    $Rnos[$p1]["Absents"][$aindex] = $individual["RNo"];
                                                    $aindex++;
                                                }
                                                if ($individual[$a] == "P") {
                                                    $Rnos[$p1]["Presents"][$pindex] = $individual["RNo"];
                                                    $pindex++;
                                                }
                                            }
                                        }
                                    }
                                    $tot = array('A' => 0, 'P' => 0);
                                    //print_r($uid);
                                    for ($w = 1; $w <= $class_total; $w++) {
                                        $tr2 = '<tr >  
									<td style="text-align:center;">' . $w . '  </td>
									<td style="text-align:center;"> ' . $uid[$w] . '  </td>';
                                        echo $tr2;
                                        //$spread.="$w \t {$uid[$w]} \t";
                                        $html .= $tr2;
                                        $pc = 0;
                                        $ac = 0;
                                        for ($l = 1; $l <= 4; $l++) {
                                            $pl = "P" . $l;
                                            if (in_array($pl, $remaining1)) {
                                                $edit_error = "";
                                                $edit_success = "";
                                                if (check('BA') or check('CR')) {
                                                    //echo $pl; print_r($confired1);
                                                    if (!in_array($pl, $confired1)) {
                                                        //echo "i am in";
                                                        //echo $pl;print_r($confired1);echo "<br>";
                                                        $fun = "";
                                                        if (array_key_exists("Absents", $Rnos[$pl]) && in_array($w, $Rnos[$pl]['Absents'])) {
                                                            $fun = "update_rno('{$date}','{$pl}','{$w}','P','{$class}');";
                                                        } else {
                                                            $fun = "update_rno('{$date}','{$pl}','{$w}','A','{$class}');";
                                                        }
                                                        $edit_error = '|  <i class="icon-edit text-success" onclick="' . $fun . '" style="cursor:pointer;"></i>';
                                                        $edit_success = '|  <i class="icon-edit text-error" onclick="' . $fun . '" style="cursor:pointer;"></i>';
                                                    }
                                                } else {
                                                    $edit_error = "";
                                                    $edit_success = "";
                                                }
                                                if (array_key_exists("Absents", $Rnos[$pl]) && in_array($w, $Rnos[$pl]['Absents'])) {
                                                    echo '<td style="text-align:center;" ><b class="text-error"> <i class="icon-remove"></i>  </b> ' . $edit_error . ' </td>';
                                                    $ac++;
                                                    $html .= "<td><font color=\"darkred\">&#x2716;</font></td>";
                                                } else {
                                                    echo '<td style="text-align:center;" ><b class="text-success"> <i class="icon-ok"></i> </b> ' . $edit_success . '</td>';
                                                    $pc++;
                                                    $html .= "<td><font color=\"green\">&#x2714;</font></td>";
                                                }
                                            } else {
                                                echo '<td></td>';
                                                $html .= '<td></td>';
                                                //$spread.=" \t";
                                            }
                                        }
                                        $tot['A'] += $ac;
                                        $tot['P'] += $pc;
                                        echo <<<a
\t\t\t\t\t\t\t\t\t<td style="text-align:center;" class="text-success"><b> {$pc} </b> </td> 
\t\t\t\t\t\t\t\t\t<td style="text-align:center;" class="text-error"><b> {$ac} </b></td>  
\t\t\t\t\t\t\t\t</tr>
\t\t\t\t\t\t\t\t
a;
                                        $html .= "<td><font color=\"green\"><b>{$pc}</b></font></td><td><font color=\"darkred\"><b>{$ac}</b></font></td></tr>";
                                        //$spread.="$pc \t $ac \n";
                                    }
                                    echo "<tr><td colspan=6 style='text-align:center;'><b>Total</b></td><td style='text-align:center;' class='text-success'><b>" . $tot['P'] . "</b></td><td style='text-align:center;' class='text-error'><b>" . $tot['A'] . "</b></td></tr>";
                                    $html .= "<tr><th colspan=6 style=\"text-align:center;\"> <b>Total</b> </th><td><b><font color=\"green\">" . $tot['P'] . "</font></b></td><td><b><font color=\"darkred\">" . $tot['A'] . "</font></b></td></tr>";
                                    //$spread.="\t \tTotal\t \t \t \t{$tot['P']} \t {$tot['A']}";
                                    echo "</tbody></table>";
                                    if ($row['Position'] == "BA") {
                                        echo <<<a
\t\t\t\t\t\t<form action='print.php' method='post' name='abc'>
\t\t\t\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Daily Report">
\t\t\t\t\t\t<input type='hidden' name='Table1' value='{$html}'>
\t\t\t\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as PDF</button></center>
\t\t\t\t\t\t</form>
a;
                                        echo <<<b
\t\t\t\t\t\t<form action='excel.php' method='post' name='abc'>
\t\t\t\t\t\t<input type='hidden' name='Title1' value="{$branch} {$class} - Daily Report">
\t\t\t\t\t\t<input type='hidden' name="sheet" value='{$html}'>
\t\t\t\t\t<center><button type="submit" class="btn btn-primary"><i class='icon-download-alt'></i>&nbsp;&nbsp;Save as Excel Sheet</button></center>
\t\t\t\t\t\t</form>
b;
                                    }
                                    echo <<<a
\t\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t</div>
\t\t\t\t\t\t\t
a;
                                } else {
                                    echo "</div><br><h6><span class='text-error'><br><br><br>No Submissions found till now ...</span></h6><br>";
                                }
                                echo "</div></div>";
                                display_footer();
                                echo "\n</body>\n</html>";
                                @mysql_close($con);
                            }
                        }
                    }
                } else {
                    display_error("Error : Invalid date");
                }
            } else {
                display_error("Error : Invalid input pattern");
            }
        } else {
            display_error("Error : Invalid no. of input arguments ");
        }
    }
}
示例#5
0
function generate_attendance($title)
{
    if (!check("CR") && !check("BA")) {
        header('location:./login.php');
    } else {
        if (!check_day()) {
            include 'config/globals.php';
            $p = $_SERVER['QUERY_STRING'];
            $reg = "/^" . $globalbranch . "[1-" . $classno . "]{1}\$/";
            if (preg_match($reg, $p)) {
                include 'config/db.php';
                include 'config/settings.php';
                include 'config/globals.php';
                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<div id="error" style="display:none;margin-top:10px;"></div>
\t\t\t
a;
                $table = '';
                //$spread='';
                $dbname = $branchyear . '_Users';
                $table = $branchyear . '_Students';
                //if(!mysql_select_db($dbname)) die(mysql_error());
                $userid = $_SESSION['UserId'];
                $q = "select Branch,Class,Position from {$table} where Id = '{$userid}'";
                $res = mysql_query($q) or die(mysql_error());
                $row = mysql_fetch_array($res);
                if ($row['Position'] == "BA") {
                    $branch = $globalbranch;
                    $class = substr($p, -1);
                } else {
                    $branch = $row['Branch'];
                    $class = $row['Class'];
                    $class1 = substr($p, -1);
                    if ($class1 != $class) {
                        //echo 'i am in';
                        echo "<script type='text/javascript'>show_error('Error: Not authorised to access {$branch}{$class1} details.');</script>";
                    }
                }
                $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');
                echo <<<a
\t\t\t
\t\t\t
\t\t
\t\t\t\t\t<div class="well well-large" style="background:#FFF;">
a;
                $tablen = $branch . $class . "_Dates";
                if (isset($_POST["submit"])) {
                    $remain = mysql_fetch_array(mysql_query("select isnull(P1_Con),isnull(P2_Con),isnull(P3_Con),isnull(P4_Con) from {$tablen};"));
                    $org = array();
                    foreach ($remain as $key => $value) {
                        if ($value == 1 && is_int($key)) {
                            $org[] = $key + 1;
                        }
                    }
                    for ($no = 1; $no <= $class_total; $no++) {
                        for ($kl = 0; $kl < count($org); $kl++) {
                            $lll = $org[$kl];
                            $resss = explode("_", $_POST["P" . $lll . "_" . $no]);
                            $dddd = $branch . $class . "_Cache";
                            $poss = $da . "_P" . $lll;
                            mysql_query("update {$dddd} set `{$poss}`='{$resss[0]}' where RNo={$no};") or die(mysql_error());
                        }
                    }
                }
                $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 ($da1 = mysql_fetch_array($ti)) {
                    $subjects[$da1[0]] = $da1[1];
                }
                //print_r($subjects);
                //$sub = $subjects[$p];
                //echo "<h5 style='text-align:center;'> Attendance Submission Details - $branch&nbsp;$class - $date</h5><br>";
                $clds = $branch . $class;
                echo <<<a
\t\t\t
\t\t\t\t<div id="step1" class="span4">     
\t\t\t\t\t<h5 class='text-info'>Today's Attendance Submission Details </h5>
\t\t\t\t\t<h6> &emsp;&emsp;&emsp; - &emsp; Listing Data submitted from CR @ {$branch}&nbsp;{$class} </h6><br>
\t\t\t\t</div>
\t\t\t\t<div id="side1" class="span7" >
\t\t\t\t\t<h6 class='text-right'><a href='./?sub'><i class='icon-home'></i> Home&nbsp;</a> </h6>
a;
                if ($row['Position'] == "BA") {
                    echo <<<a
\t\t\t\t\t<h6 class='text-right'>
a;
                    for ($cl = 1; $cl <= $classno; $cl++) {
                        echo "<a href='?{$globalbranch}{$cl}'>{$globalbranch}{$cl}</a>&emsp;";
                    }
                    echo <<<a
\t\t\t\t\t</h6>
a;
                }
                echo <<<a
\t\t\t\t</div>
\t\t\t
a;
                $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 (count($remaining1) != 0 && mysql_num_rows($q) != 0) {
                    echo '<table class="table  table-hover table-bordered "  style="padding:0px;">
						<thead>
							<tr> 
								<th style="text-align:center;"  rowspan="2" valign="top"> RNo  </th> 
								<th style="text-align:center;"  rowspan="2" valign="top"> Id  </th> 
								<th  style="text-align:center;"  > P1 </th> <th  style="text-align:center;" > P2 </th>
								<th  style="text-align:center;"  > P3 </th>  <th  style="text-align:center;"  > P4 </th> 
								<th  style="text-align:center;" rowspan=2> Presents </th> <th rowspan=2 style="text-align:center;"  > Absents </th>
							</tr>
							<tr> 
								<th  style="text-align:center;"  > ' . $subjects['P1'] . ' </th> <th  style="text-align:center;" > ' . $subjects['P2'] . ' </th>
								<th  style="text-align:center;"  > ' . $subjects['P3'] . ' </th>  <th  style="text-align:center;"  > ' . $subjects['P4'] . ' </th> 
								
							</tr>
						<form action="edit.php?' . $clds . '" method="POST">
						</thead>
						<tbody>';
                    $Rnos = array();
                    $uid = array();
                    $dbname = $branchyear . '_Attendance';
                    $table = $branch . $class . '_Attendance';
                    $q = mysql_query("select Id, RNo from {$table};") or die(mysql_error());
                    while ($res = mysql_fetch_array($q)) {
                        $uid[$res['RNo']] = $res['Id'];
                    }
                    for ($s = 0; $s < count($remaining1); $s++) {
                        $p1 = $remaining1[$s];
                        if (in_array($p1, $confired1)) {
                            $period = $p1;
                            $dbname = $branchyear . '_Attendance';
                            $table = $branch . $class . '_Attendance';
                            $q = mysql_query("select RNo,Id,`{$date}` from {$table};") or die(mysql_error());
                            $aindex = 0;
                            $pindex = 0;
                            while ($res = mysql_fetch_array($q)) {
                                $z = explode(",", $res[$date]);
                                for ($m = 0; $m < count($z); $m++) {
                                    $y = explode("_", $z[$m]);
                                    if ($y[0] == $period) {
                                        if ($y[1] == "A") {
                                            $Rnos[$p1]['Absents'][$aindex] = $res[0];
                                            $aindex++;
                                        } else {
                                            $Rnos[$p1]['Presents'][$pindex] = $res[0];
                                            $pindex++;
                                        }
                                    }
                                }
                            }
                        } else {
                            $da = date('d-m-Y');
                            $a = $da . '_' . $p1;
                            $dbname = $branchyear . '_Cache';
                            $table = $branch . $class . '_Cache';
                            $q3 = mysql_query("SELECT RNo, `" . $a . "` FROM {$table}") or die(mysql_error());
                            $aindex = 0;
                            $pindex = 0;
                            while ($individual = mysql_fetch_array($q3)) {
                                if ($individual[$a] == "A") {
                                    $Rnos[$p1]["Absents"][$aindex] = $individual["RNo"];
                                    $aindex++;
                                }
                                if ($individual[$a] == "P") {
                                    $Rnos[$p1]["Presents"][$pindex] = $individual["RNo"];
                                    $pindex++;
                                }
                            }
                        }
                    }
                    $tot = array('A' => 0, 'P' => 0);
                    $table_cl = $branch . $class . '_Dates';
                    $remain = mysql_fetch_array(mysql_query("select isnull(P1_Con),isnull(P2_Con),isnull(P3_Con),isnull(P4_Con) from {$table_cl};"));
                    for ($w = 1; $w <= $class_total; $w++) {
                        $tr2 = '<tr><td style="text-align:center;">' . $w . '</td><td style="text-align:center;"> ' . $uid[$w] . '</td>';
                        echo $tr2;
                        $pc = 0;
                        $ac = 0;
                        for ($l = 1; $l <= 4; $l++) {
                            $pl = "P" . $l;
                            if (in_array($pl, $remaining1)) {
                                if (array_key_exists("Absents", $Rnos[$pl]) && in_array($w, $Rnos[$pl]['Absents'])) {
                                    $disp = $remain[$l - 1] == 1 ? '<input type="text" name="' . $pl . "_" . $w . '" class="input-mini" value="A"></input>' : '<i class="icon-remove"></i>';
                                    echo '<td style="text-align:center;" class="text-error"><b>' . $disp . '</b></td>';
                                    $ac++;
                                } else {
                                    $disp = $remain[$l - 1] == 1 ? '<input type="text" name="' . $pl . "_" . $w . '" class="input-mini" value="P"></input>' : '<i class="icon-ok"></i>';
                                    echo '<td style="text-align:center;" class="text-success"><b>' . $disp . '</b></td>';
                                    $pc++;
                                }
                            } else {
                                echo '<td></td>';
                            }
                        }
                        $tot['A'] += $ac;
                        $tot['P'] += $pc;
                        echo <<<a
\t\t\t\t\t\t<td style="text-align:center;" class="text-success"><b> {$pc} </b> </td> 
\t\t\t\t\t\t<td style="text-align:center;" class="text-error"><b> {$ac} </b></td>  
\t\t\t\t\t</tr>
\t\t\t\t\t
a;
                    }
                    echo "<tr><td colspan=6 style='text-align:center;'><b>Total</b></td><td style='text-align:center;' class='text-success'><b>" . $tot['P'] . "</b></td><td style='text-align:center;' class='text-error'><b>" . $tot['A'] . "</b></td></tr>";
                    echo "</tbody></table>";
                    echo "<center><button type='submit' name='submit' class='btn btn-primary'><i class='icon-upload'></i>&nbsp;&nbsp;Update Now </button></center></form>";
                    echo "</div></div>";
                } else {
                    echo "<br><h6><span class='text-error'><br><br><br>No Submissions found till now ...</span></h6><br></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();
        }
    }
}