function changecr($title) { /* checks the user login and * redirecting user to login page */ if (!check_login()) { header('location:login.php'); } else { include 'config/globals.php'; /* taking the query string by using the regular expression */ $p = $_SERVER['QUERY_STRING']; $reg = "/^" . $globalbranch . "[1-" . $classno . "]{1}\$/"; $reg1 = "/^all\$/"; if (preg_match($reg, $p) or preg_match($reg1, $p)) { /* including the necessary configuration php files */ include 'config/db.php'; include 'config/settings.php'; /* defining the table names */ $dbname = $branchyear . '_Users'; $table = $branchyear . '_CRs'; $table1 = $branchyear . '_Students'; //if(!mysql_select_db($dbname)) die(mysql_error()); //$branch = $row['Branch']; its not required $class = substr($p, -1); /* Getting the users details from joining the two tables */ if ($p == 'all') { $q = "select {$table}.Name as Name, {$table}.Gender as Gender, {$table}.Id as Id,PhoneNo, `{$table1}`.`Class` as `Class` from {$table},{$table1} where `{$table}`.`Id` = `{$table1}`.`Id` order by `{$table1}`.`Class` Desc;"; } else { $q = "select {$table}.Name as Name, {$table}.Gender as Gender, {$table}.Id as Id,PhoneNo from {$table},{$table1} where `{$table}`.`Id` = `{$table1}`.`Id` and `{$table}`.`Class` = '{$class}';"; } $res = mysql_query($q) or die(mysql_error()); echo "<!DOCTYPE html>\n<html>\n"; /* including the header java scripts and css files */ display_headers($title); echo "\n<body>"; /* displayin the header menu */ menu(); $br = $p == 'all' ? $globalbranch : $p; $cls1 = $p == 'all' ? '<th style="text-align:center;" class="span1"> Class </th>' : ""; echo <<<a \t\t<div class='container'> \t\t\t<div id="error" style="display:none;"></div> \t\t\t<div class='row'> \t\t\t<div class='span9'> \t\t\t\t<div class="well well-large" style="background:#FFF;"> \t\t\t\t<h5 class='text-info'>CRs @ {$br} </h5> \t\t\t\t<h6>     -   Listing all CRs in {$br} </h6><br> \t\t\t\t<table class="table table-hover table-bordered " style="padding:0px;"> \t\t\t\t<thead> \t\t\t\t\t<tr> <th class="span1" style="text-align:center;" > Id </th><th style="text-align:center;" class="span3"> Name </th> {$cls1} \t\t\t\t\t<th style="text-align:center;" class="span1"> Gender </th> <th class="span1" style="text-align:center;"> Contact No </th> </tr> \t\t\t\t</thead> \t\t\t\t<tbody> a; while ($row = mysql_fetch_array($res)) { $gender = $row['Gender']; $d = $dict[$gender . '1']; $id = $row['Id']; $contact = $row['PhoneNo']; $cls = $p == 'all' ? '<td style="text-align:center;">' . $globalbranch . " " . $row['Class'] . '</td>' : ""; $name = ucwords(strtolower($row['Name'])); echo <<<a \t\t\t\t\t \t\t\t<tr > \t\t\t<td style="text-align:center;" > {$id} </td> \t\t\t<td > {$name} </td> \t\t\t{$cls} \t\t\t<td style="text-align:center;"> {$d} </td> \t\t\t<td style="text-align:center;" class="text-success"><b> {$contact} </b> </td> \t\t\t</tr> a; } echo <<<a \t\t\t\t</tbody> \t\t\t </table> \t\t\t</div>\t \t\t\t</div> \t\t\t<div class='span3'> a; go_home(); echo '<ul class="nav nav nav-tabs nav-stacked"> <li><a href=\'?all\'>All CRs <i class="icon-chevron-right pull-left" style="padding-top:5px;"></i></a> </li></ul>'; cr_classes($classno, $globalbranch); echo "</div></div></div>"; display_footer(); echo "\n</body>\n</html>"; } else { echo "<script type='text/javascript'>document.location.href='404.php';</script>"; } } }
function changecr($title) { if (!check('BA') and !check('SA')) { header('location:login.php'); } else { 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'; $dbname = $branchyear . '_Users'; $table = $branchyear . '_Students'; //if(!mysql_select_db($dbname)) die(mysql_error()); $userid = $_SESSION['UserId']; $q = "select Branch from {$table} where Id = '{$userid}'"; $res = mysql_query($q) or die(mysql_error()); $row = mysql_fetch_array($res); $branch = $row['Branch']; $class = substr($p, -1); echo "<!DOCTYPE html>\n<html>\n"; display_headers($title); echo "\n<body>"; menu(); $array = array_merge(range(0, 9), range('a', 'z')); shuffle($array); $crkey = ""; for ($i = 0; $i < 9; $i++) { $crkey .= $array[$i]; } echo <<<a \t\t\t\t<div class='container'> \t\t\t\t\t<div id="error" style="display:none;"></div> \t\t\t\t\t<div class='row'> \t\t\t\t\t<div class='span9'> \t\t\t\t\t\t<div class="well well-large" style="background:#FFF;height:450px;"> a; if (isset($_POST["Idno"])) { $id = addslashes($_POST['Idno']); $gender = addslashes($_POST['Gender']); $key = addslashes($_POST['Key']); if (strlen(trim($id)) == 0) { echo "<script>show_error('Error : Id should not be null');</script>"; exit; } if (strlen(trim($gender)) == 0) { echo "<script>show_error('Error : CR Gender should not be null');</script>"; exit; } if (strlen(trim($key)) == 0) { echo "<script>show_error('Error : Key should not be null');</script>"; exit; } include 'config/db.php'; include 'config/settings.php'; $dbname = $branchyear . '_Users'; $table = $branchyear . '_Students'; //if(!mysql_select_db($dbname)) {die(mysql_error());} $userid = $id; $q = "select Name,Branch,Class,Gender from {$table} where Id = '{$userid}'"; $res = mysql_query($q) or die(mysql_error()); $row = mysql_fetch_array($res); $name = ucwords(strtolower($row['Name'])); $branch = $row['Branch']; $class1 = $row['Class']; $gender1 = $row['Gender']; $branch = $globalbranch; $d = $dict[$gender . '1']; if ($class1 == $class && $gender1 == $gender) { $table = $branchyear . '_CRs'; $old_id = mysql_fetch_array(mysql_query("Select Id from {$table} where Class = '{$class}' and Gender = '{$gender}';"))['Id']; $q = mysql_query("delete from {$table} where Class = '{$class}' and Gender = '{$gender}';") or die(mysql_error()); $q1 = mysql_query("insert into {$table} ( `Id`, `Name`, `Gender`, `Branch`,`Class`, `Key`) values ( '{$id}', '{$name}' , '{$gender}', '{$branch}', '{$class}', '{$key}');") or die(mysql_error()); insert_log("Changing {$branch} {$class} {$d} CR to {$id}"); $dbname = $branchyear . '_Logs'; $table = $branchyear . '_Notifications'; //if(!mysql_select_db($dbname)) {die(mysql_error());} $datetime = date('d/m/Y H:m:s'); $ip = $_SERVER['REMOTE_ADDR']; $to1 = $branch . $class . "@students"; $query = mysql_query("INSERT INTO " . $table . "(`To`,`From`,`Subject`,`Message`,`DateTime`,`IP`) VALUES('{$to1}','" . $_SESSION['UserId'] . "','Changing the {$d} CR of {$branch} {$class}','Dear Students,<br>Please Notice that, {$branch} {$class} {$d} CR has been changed to <br> {$name}, {$id}.','{$datetime}','{$ip}');") or die(mysql_error()); $table = $dbname = $branchyear . '_Students'; $query = mysql_query("update {$table} set Position = 'CR' where Id = '{$id}'") or die(mysql_error()); $query1 = mysql_query("update {$table} set Position = 'S' where Id = '{$old_id}'") or die(mysql_error()); echo "<script>show_success('{$branch} {$class} {$d} CR has been updated with {$name} and security key <u class=\\'text-error\\'>{$key}</u> ');</script>"; } else { echo "<script>show_error('<b>Error </b> : <b>{$id}</b> is not from the <b>{$branch} {$class} {$d}</b> Please try again.. ');</script>"; } } echo <<<a \t\t\t<div id="step1"> \t\t\t<h4>Change CR of {$branch} {$class} </h4> \t\t\t<h6>      Provide Details of New CR </h6><br> \t\t\t<form action="?{$p}" method="POST" onsubmit="return viewcr('{$branch}',{$class});" id="changecr"> \t\t\t<h5>Gender : </h5> \t\t\t<label class="radio inline"><input type="radio" value="M" name="Gender" id="Male" /> Male </label> \t\t\t<label class="radio inline"><input type="radio" value="F" name="Gender" id="Female" /> Female </label> \t\t\t<br><br> \t\t\t<h5>New CR ID No : </h5> \t\t\t<input type="text" class="input-large" placeholder="N090001" id="Idno" name="IdNo" maxlength="7" /><br> \t\t\t<!--<h5>Security Key : </h5>--> \t\t\t<input type="hidden" class="input-large" placeholder="Password" readonly=readonly name="Key" value="{$crkey}" ><br> \t\t\t<input type="submit" class="btn btn-primary" name="change" value = "Continue →" /> \t\t\t</form>\t \t\t\t<form action="?{$p}" method='post' id='sub2'> \t\t\t<div id="confirm"> \t\t\t\t<div id="cr" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="useridlabel" aria-hidden="true"> \t\t\t\t<div class="modal-header"> \t\t\t\t<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> \t\t\t\t<h4 id="useridlabel">Caution</h4> \t\t\t\t</div> \t\t\t\t<div class="modal-body" id='mbody'></div> \t\t\t\t<div class="modal-footer"> \t\t\t\t<button class="btn btn-danger" aria-hidden="true" type="submit" onclick="a();">Confirm & Replace </button> \t\t\t\t<button class="btn btn-primary" aria-hidden="true" data-dismiss='modal' > Cancel </button> \t\t\t\t</div> \t\t\t</div> \t\t\t\t<input type="hidden" placeholder="Password" readonly=readonly name="Gender" value="" id='gender1'> \t\t\t\t<input type="hidden" placeholder="Password" readonly=readonly name="Idno" value="" id='idno1'> \t\t\t\t<input type="hidden" class="input-large" placeholder="Password" readonly=readonly name="Key" value="{$crkey}" > \t\t\t</form> \t\t\t</div> \t\t\t</div>\t\t a; echo <<<b \t\t\t\t \t\t\t\t</div>\t \t\t\t\t</div> \t\t\t\t<div class='span3'> b; go_home(); cr_classes($classno, $globalbranch); echo "</div></div></div>"; display_footer(); echo "\n</body>\n</html>"; } else { echo "<script type='text/javascript'>document.location.href='404.php';</script>"; } } }