Example #1
0
File: ssap2.php Project: ItsJimi/42
function compare1($a, $b)
{
    $a = strtolower($a);
    $b = strtolower($b);
    if (is_alpha($a)) {
        $val_a = 1;
    } else {
        if (is_numeric($a)) {
            $val_a = 2;
        } else {
            $val_a = 3;
        }
    }
    if (is_alpha($b)) {
        $val_b = 1;
    } else {
        if (is_numeric($b)) {
            $val_b = 2;
        } else {
            $val_b = 3;
        }
    }
    if ($val_a != $val_b) {
        return $val_a - $val_b;
    }
    return strcmp($a, $b);
}
Example #2
0
function handleCreateCourse()
{
    global $classID, $className, $classes, $configFolderName, $dbConnection;
    global $session, $department, $courseNo, $sectionNo, $season;
    global $yteststudent_hashed_id, $iteststu_guest_id, $bteststu_basic_id;
    global $command, $commandState;
    global $Jenny_hashed_id, $Thomas_hashed_id;
    // get the command itself
    $command = Commands::CreateCourse;
    // get the state of the command
    $commandState = CommandStates::Execute;
    printOutputPageHeading($commandState);
    if (!empty($_POST)) {
        if (!(array_key_exists('session', $_POST) && array_key_exists('season', $_POST))) {
            $errors .= "Fatal Error: Session Year or Season is empty. This may be a bug<br/><br/>";
        } else {
            $session = $_POST['session'];
            $season = $_POST['season'];
        }
        $is_SIS_course = $_POST['is_SIS_course'];
        if ($is_SIS_course == "yes") {
            $department = $_POST['department'];
            $courseNo = $_POST['course_number'];
            $sectionNo = $_POST['section_number'];
            $department = strtoupper($department);
        } else {
            $className = $_POST['course_name'];
            if (is_null($className) || strlen($className) == 0) {
                $errors .= "Error: You must enter a class name<br/>";
            }
        }
        $instructorIDs = $_POST['instructor_id'];
        $taIDs = $_POST['TA_ids'];
        // validate inputs
        if (!empty($instructorIDs)) {
            $instructorIDs = UTIL_textArea2Array($instructorIDs);
        } else {
            $errors .= "Fatal Error: Instructor List is Empty!<br/><br/>";
        }
        if (!empty($taIDs)) {
            $taIDs = UTIL_textArea2Array($taIDs);
        }
        // Extra admin hash ids, TODO: factor into an array for neatness
        $extraAdminHashIDs = array();
        $extraAdminHashIDs[] = $Jenny_hashed_id;
        $extraAdminHashIDs[] = $Thomas_hashed_id;
        // Extra student hash ids
        $extraStudentHashIDs = array();
        $extraStudentHashIDs[] = $yteststudent_hashed_id;
        if ($is_SIS_course == "yes") {
            if (is_null($courseNo) || strlen($courseNo) == 0) {
                $errors .= "Error: you must enter a course number<br/>";
            } else {
                if (is_numeric(substr($courseNo, 0, 3))) {
                    if (strlen($courseNo) == 4) {
                        if (!is_alpha(substr($courseNo, 3, 1))) {
                            $errors .= "Error: course number must be three digits plus an optional letter, ex. '300' or '300B'<br/><br/>";
                        }
                    }
                } else {
                    $errors .= "Error: course number must be three digits plus an optional letter, ex. '301' or '301A'<br/><br/>";
                }
            }
            if (is_null($sectionNo) || strlen($sectionNo) == 0) {
                $errors .= "Error: you must enter a section number<br/>";
            } else {
                // pad section number to three digits
                while (strlen($sectionNo) < 3) {
                    $sectionNo = "0" . $sectionNo;
                }
            }
            // Assemble the name
            $className = getCourseName($department, $courseNo, $sectionNo);
            $className = $className . "_{$session}{$season}";
            if (in_array($className, $classes)) {
                $errors .= "Error: {$className} already exists<br/><br/>";
            }
        } else {
            $className = $className . "_{$session}{$season}";
            if (in_array($className, $classes)) {
                $errors .= "Error: {$className} already exists<br/><br/>";
            }
        }
        if (empty($errors)) {
            print "<b>Course Name to be Created: {$className}</b><br/><br/>";
            print "<b>Instructors List:</b><br/>";
            DEBUG_printSimpleArray($instructorIDs, 1);
            print "<br/><br/>";
            print "<b>TA's List:</b><br/>";
            DEBUG_printSimpleArray($taIDs, 1);
            print "<br/><br/>";
            print "<b>Creating Instructor Account(s) if Not Yet Existed</b><br/>";
            if (!empty($instructorIDs)) {
                // The rest of the debug messages (SQL output) goes into a text area, for neatness
                print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                $instructorIDs = createUsers($instructorIDs, INSTRUCTOR, $dbConnection);
                print "</div></div><br/>";
            } else {
                print "Nothing To Do...<br/><br/>";
            }
            print "<b>";
            if (!empty($taIDs)) {
                print "Creating Teaching Assistant Account(s) if Not Yet Existed<br/>";
            } else {
                print "There are no TA's in the Course (for now)<br/><br/>";
            }
            print "</b>";
            if (!empty($taIDs)) {
                // The rest of the debug messages (SQL output) goes into a text area, for neatness
                print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                $taIDs = createUsers($taIDs, TA, $dbConnection);
                print "</div></div><br/>";
            }
            print "<b>";
            if (!empty($extraAdminHashIDs)) {
                print "Creating Extra Administrator Account(s) - Arts Helpdesk, LC, etc.<br/>";
            } else {
                print "There are no extra admin accounts in the course for now.<br/><br/>";
            }
            print "</b>";
            $extraAdminIDs = null;
            if (!empty($extraAdminHashIDs)) {
                // The rest of the debug messages (SQL output) goes into a text area, for neatness
                print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                $extraAdminIDs = createUsers($extraAdminHashIDs, INSTRUCTOR, $dbConnection, true);
                print "</div></div><br/>";
            }
            print "<b>";
            if (!empty($extraStudentHashIDs)) {
                print "Creating Extra Student Account(s) for Testing (yteststudent, iteststu, bteststu)<br/>";
            } else {
                print "There are no extra student accounts in the course for now.<br/><br/>";
            }
            print "</b>";
            $extraStudentIDs = null;
            if (!empty($extraStudentHashIDs)) {
                // The rest of the debug messages (SQL output) goes into a text area, for neatness
                print "<div style=\"min-width:1024px;text-align:center;font-size:75%\">";
                print "<div style=\"margin-left:auto;margin-right:auto;border:1px solid gray;height:200px;width:1030px;white-space:pre-wrap;overflow:scroll;\">";
                $extraStudentIDs = createUsers($extraStudentHashIDs, STUDENT, $dbConnection, true);
                print "</div></div><br/>";
            }
            // initial student list
            $studentIDs = $extraStudentIDs;
            // create and populate class
            $classID = createClass($className, $dbConnection);
            // merge admin lists
            $instructorIDs = array_merge($instructorIDs, $extraAdminIDs);
            addInstructorAndTAs($classID, $instructorIDs, $taIDs, $dbConnection);
            // create default groups
            $users = new users();
            print "<b>Create Default Group {$className}" . "_everyone</b><br/><br/>";
            $groupName = $className . "_everyone";
            // This can deal with a null userID list, only instructorID and classID is utterly necessary
            $users->createGroup($groupName, $studentIDs, $instructorIDs, $classID);
            // Instructors and TA
            print "<b>Create Default Group {$className}" . "_instructorAndTA</b><br/><br/>";
            $groupName = $className . "_instructorAndTA";
            $users->createGroup($groupName, null, $instructorIDs, $classID);
            // set default UI for each user, first, let's merge all the arrays created so far.
            if (empty($taIDs)) {
                $allIDs = array_merge($instructorIDs, $studentIDs);
            } else {
                $allIDs = array_merge($instructorIDs, $taIDs, $studentIDs);
            }
            UTIL_setDefaultUISettings($allIDs);
            $users->close();
            mysql_close($dbConnection);
            print "<h3>Course Creation Successful!</h3>";
            printOutputPageFooting($commandState, $className);
        } else {
            print "{$errors}";
            printOutputPageFooting(CommandStates::Error, $className);
        }
    } else {
        print "<br/><span style=\"color:red;font-weight:bold\">\r\n\t\t\t\tFATAL ERROR! POST parameter list empty. You may have found a bug.<br/>\r\n\t\t\t\tPlease email thomas.dang@ubc.ca with as much info as possible of the context when this error appears.<br/>\r\n\t\t\t\t</span>\r\n\t\t\t\t<br/>";
        printOutputPageFooting(CommandStates::Error);
    }
}
Example #3
0
/**
	This function will split a sentence into separate words.

	Sentences will be split on normal word boundaries, such as
	spaces,tabs,newlines, but also when a bracket (,{,[,],},) are
	encountered.  All space will be preserved however and restored
	to the final string.

	This function will also recognise Roman numerals from I to XX (1-20) 
	and if they are already UPPERCASE, will maintain case.

	This function differs from ucwords, in that it will set all 
	other characters in a word to lowercase!
*/
function initcap($text)
{
    $word = '';
    $rtext = '';
    for ($i = 0; $i < strlen($text); $i++) {
        // We might be in the middle of a word.
        if (strlen($word) > 0 || is_alpha($text[$i])) {
            // test for end of word.
            if (strlen($word) > 0 && is_nonword_char($text[$i])) {
                $rtext .= ucword($word);
                $word = '';
                $rtext .= $text[$i];
            } else {
                $word .= $text[$i];
            }
        } else {
            //just copy it to return array.
            $rtext .= $text[$i];
        }
    }
    // Do final word.
    if (strlen($word) > 0) {
        $rtext .= ucword($word);
        $word = '';
    }
    return $rtext;
}
Example #4
0
 }
 if (($cert_type == 'email' || $cert_type == 'email_signing') && !$passwdv) {
     $er .= 'Missing Certificate Password Verification "Again"<br>';
 }
 if ($passwd && strlen($passwd) < 8) {
     $er .= 'Certificate password is too short.<br>';
 }
 if ($passwd and $passwd != $passwdv) {
     $er .= 'Password and password verification do not match.<br>';
 }
 //if ( ! is_alnum($passwd) or ! is_alnum($passwdv) )
 //	$er .= 'Password contains invalid characters.<br>';
 if ($email && !is_email($email)) {
     $er .= 'E-mail address (' . htvar($email) . ') may be invalid.<br>';
 }
 if ($country && !is_alpha($country)) {
     # Check if country code only contains alphabetic characters
     $er .= 'Country code is invalid.';
 }
 if ($er) {
     $er = '<h2>ERROR(S) IN FORM:</h2><h4><blockquote>' . $er . '</blockquote></h4>';
 }
 if ($email && ($serial = CAdb_in($email, $common_name))) {
     $er = '';
     $certtext = CA_cert_text($serial);
     $er .= '<h2>A valid certificate already exists for ' . htvar("{$common_name}  <{$email}>") . '</h2>';
     $er .= '</font><blockquote><pre> ' . htvar($certtext) . ' </pre></blockquote>';
 }
 if ($er) {
     printHeader();
     ?>
Example #5
0
function VerifyBadgeFormat($BadgeID)
{
    if (blank($BadgeID)) {
        return true;
    }
    if (strlen($BadgeID) != 4) {
        return false;
    }
    if (!is_alpha(substr($BadgeID, 0, 1))) {
        return false;
    }
    if (!is_digit(substr($BadgeID, 1, 1))) {
        return false;
    }
    if (!is_digit(substr($BadgeID, 2, 1))) {
        return false;
    }
    if (!is_digit(substr($BadgeID, 3, 1))) {
        return false;
    }
    return true;
}
Example #6
0
        $valid = false;
    }
    if (!is_alpha($author)) {
        $authorError = 'Please enter an valid Author';
        $valid = false;
    }
    if (empty($year)) {
        $yearError = 'Please enter a valid Year';
        $valid = false;
    } else {
        if (!is_number($year)) {
            $yearError = 'Please enter a valid Year asdsad';
            $valid = false;
        }
    }
    if (!is_alpha($description)) {
        $descriptionError = 'Please enter a valid Description';
        $valid = false;
    }
    // update data
    if ($valid) {
        $sql = "UPDATE books  set title = ?, author = ?, year =?, description =? WHERE id = ?";
        $query = $db->prepare($sql);
        $query->execute(array($title, $author, $year, $description, $id));
        header("Location: journal.php");
    }
} else {
    $sql = "SELECT * FROM books where id = ?";
    $query = $db->prepare($sql);
    $query->execute(array($id));
    $data = $query->fetch(PDO::FETCH_ASSOC);
Example #7
0
        return $tab;
    }
}
function is_alpha($char)
{
    if (isset($char)) {
        return ereg("^[a-zA-Z]*\$", $char) ? TRUE : FALSE;
    }
}
if ($argc > 1) {
    unset($argv[0]);
    foreach ($argv as $element) {
        $epur = array_merge($epur, ft_split($element));
    }
    for ($index = 0; $index <= count($epur); $index++) {
        if (is_alpha($epur[$index][0])) {
            $let = $let . " " . $epur[$index];
        } else {
            if (is_numeric($epur[$index][0])) {
                $num[] = $epur[$index];
            } else {
                $spe = $spe . " " . $epur[$index];
            }
        }
    }
    array_multisort($num, SORT_ASC, SORT_STRING);
    $ret = array_merge(ft_split($let), $num, ft_split($spe));
    foreach ($ret as $element) {
        echo $element . "\n";
    }
}
function tmve_do_actions()
{
    $mesg = '';
    $emesg = '';
    if (isset($_GET['add_ele'])) {
        if (!empty($_GET['add_ele'])) {
            if (is_alpha($_GET['add_ele'])) {
                if (tmve_add_element($_GET['add_ele'])) {
                    $mesg = 'Element \'' . $_GET['add_ele'] . '\' added. Refresh TinyMCE (ctrl + F5).';
                } else {
                    $emesg = 'Element \'' . $_GET['add_ele'] . '\' already exists.';
                }
            } else {
                $emesg = "New element must contain letters only.";
            }
        } else {
            $emesg = "New element can't be empty.";
        }
    } else {
        if (isset($_GET['rm_ele'])) {
            if (!empty($_GET['rm_ele'])) {
                if (tmve_remove_element($_GET['rm_ele'])) {
                    $mesg = 'Element \'' . $_GET['rm_ele'] . '\' removed.';
                } else {
                    $emesg = 'Error. Element \'' . $_GET['rm_ele'] . '\' not removed.';
                }
            } else {
                $emesg = "Element can't be empty.";
            }
        } else {
            if (isset($_GET['add_attr'])) {
                if (!empty($_GET['add_attr'])) {
                    if (is_alpha($_GET['add_attr'])) {
                        if (tmve_add_attribute($_GET['ele'], $_GET['add_attr'])) {
                            $mesg = 'Attribute \'' . $_GET['add_attr'] . '\' added to element \'' . $_GET['ele'] . '\'. Refresh TinyMCE (ctrl + F5)';
                        } else {
                            $emesg = 'Attribute \'' . $_GET['add_attr'] . '\' already exists.';
                        }
                    } else {
                        $emesg = "New attribute must contain letters only.";
                    }
                } else {
                    $emesg = "New attribute can't be empty.";
                }
            } else {
                if (isset($_GET['rm_attr'])) {
                    if (!empty($_GET['rm_attr'])) {
                        if (tmve_remove_attribute($_GET['ele'], $_GET['rm_attr'])) {
                            $mesg = 'Attribute \'' . $_GET['rm_attr'] . '\' removed from element \'' . $_GET['ele'] . '\'.';
                        } else {
                            $emesg = 'Error. Attribute \'' . $_GET['rm_ele'] . '\' not removed.';
                        }
                    } else {
                        $emesg = "Attribute can't be empty.";
                    }
                } else {
                    if (isset($_GET['delete_on_deactivate'])) {
                        if ($_GET['delete_on_deactivate'] == "yes") {
                            update_option('tmve_cascade_on_deactivate', "true");
                            $mesg = 'Deactivation settings changed. Plugin tables and settings deleted on deactivation.';
                        } else {
                            if ($_GET['delete_on_deactivate'] == "no") {
                                update_option('tmve_cascade_on_deactivate', "false");
                                $mesg = 'Deactivation settings changed. Plugin tables and settings saved on deactivation.';
                            } else {
                                $emesg = 'Invalid deactivation settings used.';
                            }
                        }
                    }
                }
            }
        }
    }
    if (!empty($mesg)) {
        echo '<div id="message" class="updated fade"><p>' . $mesg . '</p></div>';
    }
    if (!empty($emesg)) {
        echo '<div id="message" class="error fade" style="background-color: red"><p>' . $emesg . '</p></div>';
    }
}
Example #9
0
function csort($array, $column, $ascdec = SORT_ASC)
{
    if (sizeof($array) == 0) {
        return $array;
    }
    foreach ($array as $x) {
        $sortarr[] = $x[$column];
    }
    #usort($sortarr, "nameComparator");
    #Seems to work almost properly now
    array_multisort($sortarr, $ascdec, SORT_NATURAL | SORT_FLAG_CASE | SORT_REGULAR, $array);
    #array_multisort($sortarr, $ascdec, SORT_REGULAR, $array);
    print "Time is: " . date('D, d M Y H:i:s ', $_SERVER['REQUEST_TIME']) . '<br>';
    print implode(" . . . ", $sortarr) . '<br>';
    print "Alphabetic: " . (int) is_alpha("Hi") . " ";
    return $array;
}