Exemple #1
0
/**
 * Remove the teacher downlaods for $tid both in db and filesystem.
 *
 * @global mixed $_CONF
 * @param int $tid
 * @param int $cid
 * @return Array {string body and boolean state)
 */
function remove_teacher_downloads($tid, $cid)
{
    global $_CONF;
    global $db;
    $sql = "SELECT u_name from users where user_id=" . $tid;
    $result = $db->query($sql);
    $row = $result->fetch_assoc();
    $u_name = $row['u_name'];
    $sql = "SELECT short_name from ed_centers where center_id=" . $cid;
    $result = $db->query($sql);
    $row = $result->fetch_assoc();
    $short_name = $row['short_name'];
    $path = $_CONF['configPath'] . "downloads/" . $short_name . "/" . $u_name . "/";
    $dl_error = array();
    $dl_error['state'] = false;
    $dl_error['title'] = "Error Removing Downloads";
    $dl_error['body'] = "";
    $result = get_downloads_for_teacher($tid, $cid);
    if ($result) {
        while ($row = $result->fetch_assoc()) {
            /** remove from file system **/
            if (is_file($path . $row['filename'])) {
                if (!unlink($path . $row['filename'])) {
                    $dl_error['body'] .= "There was a problem removing file " . $path . $row['filename'] . " from the filesystem.<br>";
                    $dl_error['state'] = true;
                } else {
                    $sql2 = "DELETE from download2course where download_id=" . $row['download_id'];
                    if ($result2 = $db->query($sql2)) {
                        $sql2 = "DELETE from downloads where download_id=" . $row['download_id'];
                        if (!($result2 = $db->query($sql2))) {
                            $dl_error['body'] .= "Unable to remove Download {id=" . $row['download_id'] . "} from downloads<br>";
                            $dl_error['state'] = true;
                        }
                    } else {
                        $dl_error['body'] .= "Unable to remove Download {id=" . $row['download_id'] . "} from download2course<br>";
                        $dl_error['state'] = true;
                    }
                }
            } else {
                $dl_error['body'] .= "The file " . $path . $row['filename'] . " seems to be missing.<br>";
                $dl_error['state'] = true;
            }
        }
    }
    if (!$dl_error['state']) {
        //deltree($path);
        del_dir($path);
    }
    return $dl_error;
}
Exemple #2
0
     		generate the upload form... 
     	**/
     $t = "Upload a file";
     $b = "<form id=\"upload_form\" enctype=\"multipart/form-data\" action=index.php?lev=" . $_SESSION[$_CONF['sess_name'] . '_lev'] . "&cat=" . $_SESSION[$_CONF['sess_name'] . '_cat'] . " method=\"post\" onSubmit=\"return validateForm(this);\">\n\t\t\t\t<center>\n\t\t\t\t<table border=0 cellspacin=2 cellpadding=2>\n\t\t\t\t<tr>\n\t\t\t\t<td align=right>Please Select a Class :</td>\n\t\t\t\t<td>";
     foreach ($courses as $cid => $cname) {
         $b .= " &nbsp;&nbsp;" . $cname . "<input type=checkbox name=enableFor_" . $cid . " value=" . $cid . " />";
     }
     $b .= "\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td align=right>Please select the file to upload :</td>\n\t\t\t\t<td align=left><input class=\"validate[required]\" id=\"upload_file\" name=\"upload_file\" type=\"file\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td align=right>Please provide a Title :</td>\n\t\t\t\t<td align=left><input class=\"validate[required]\" id=\"title\" name=\"title\" type=text size=20></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td align=right valign=top>Description :</td> \n\t\t\t\t<td align=left><textarea name=description rows=6 cols=30></textarea></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td colspan=2 align=center><input type=\"submit\" name=\"upload\" value=\"Upload\"></td>\n\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t\t</center>\n\t\t\t\t</FORM>";
     $main .= make_box($t, $b);
 }
 /** 
 	Manage Downloads.
 	Should display any downloads in the system for ME
 	Get the courses in current school year it is set for also
 **/
 $result = get_downloads_for_teacher($_SESSION[$_CONF['sess_name'] . '_myUID'], $_SESSION[$_CONF['sess_name'] . '_myCenter']);
 if ($result && $result->num_rows != 0) {
     $t = "Manage Downloads";
     $b = "";
     $b = "<center><table border=0 cellspacing=2 cellpadding=2>";
     while ($row = $result->fetch_assoc()) {
         /** need to get courses for this download **/
         $b .= "<tr>";
         $b .= "<td valign=top nowrap><b>" . $row['title'] . " :</b></td>\n";
         $b .= "<td valign=top>" . $row['description'] . "</td>\n";
         $b .= "<td>\n";
         $b .= "<form action=index.php?lev=" . $_SESSION[$_CONF['sess_name'] . '_lev'] . "&cat=" . $_SESSION[$_CONF['sess_name'] . '_cat'] . " method=\"post\">\n";
         $b .= "<input type=submit name=download value=Download />&nbsp;\n";
         $b .= "<input type=submit name=edit value=Edit />\n";
         $b .= "<input type=submit name=delete value=**Delete** onClick=\"return confirmDelete();\"/>\n";
         $b .= "<input type=hidden name=d_id value=" . $row['download_id'] . " />\n";