Ejemplo n.º 1
0
function addfile($id, $new_project = false)
{
    if (!count($_POST)) {
        return null;
    }
    $conf = configurations();
    $date = new MongoDate();
    $tstamp = $date->sec;
    $con = new Mongo();
    $db = $con->{$conf}['base']->{$conf}['project'];
    if ($new_project) {
        $project['name'] = $id;
    } else {
        $project = $db->findOne(array('_id' => new MongoId($id)));
    }
    if (isset($project['name'])) {
        $projectname = $project['name'];
    } else {
        return 'attack';
    }
    if (is_null($_POST['projectfile']) || is_null($_POST['projectversion'] || is_null($_POST['changelog']))) {
        return 'fieldmissing';
    }
    if (is_array(myfilter($_POST['projectversion'], 'version'))) {
        return getvalue(myfilter($_POST['projectversion'], 'version'), 1);
    }
    if (is_array(myfilter($_POST['changelog'], 'changelog'))) {
        return getvalue(myfilter($_POST['changelog'], 'changelog'), 1);
    }
    if (!is_array($_POST['projectfile']) || !is_array($_POST['projectos']) || !is_array($_POST['projectarch'])) {
        return 'attack';
    }
    $version = myfilter($_POST['projectversion'], 'version');
    foreach ($_POST['projectfile'] as $key => $value) {
        if (!is_null($value) && is_file($value) && getvalue(explode('/', $value), 0) == $conf['upload_dir']) {
            if (!in_array($_POST['projectos'][$key], $conf['os']) || !in_array($_POST['projectarch'][$key], $conf['arch'])) {
                return 'fieldcheck';
            }
            $checkinit = $_POST['projectos'][$key] . $_POST['projectarch'][$key];
            if (isset($checkos) && isset($checkfile)) {
                if (in_array($checkinit, $checkos, true) || in_array($value, $checkfile, true)) {
                    return 'fieldcheck';
                }
            }
            $checkos[$key] = $checkinit;
            $checkfile[$key] = $value;
            //var_dump($checkfile);
            $sha1 = sha1_file($value);
            $filename = file_name($projectname) . '-' . file_name(myfilter($_POST['projectversion'], 'version')) . '-' . file_name($_POST['projectos'][$key]) . '-' . file_name($_POST['projectarch'][$key]) . '.' . getvalue(pathinfo($value), 'extension');
            $path = 'files/' . file_name($projectname) . '/' . file_name($version) . '/' . file_name($_POST['projectos'][$key]) . '/' . file_name($_POST['projectarch'][$key]) . '/' . $sha1 . '/' . $filename;
            $length = filesize($value);
            $query['files'][$_POST['projectos'][$key]][$_POST['projectarch'][$key]] = array('sha1' => $sha1, 'filename' => $filename, 'path' => $path, 'length' => $length, 'date' => $date);
            $filesmv[$key] = array('dir' => 'files/' . file_name($projectname) . '/' . file_name($version) . '/' . file_name($_POST['projectos'][$key]) . '/' . file_name($_POST['projectarch'][$key]) . '/' . $sha1, 'file' => $value, 'path' => $path);
        }
    }
    $query['version'] = $version;
    $query['changelog'] = myfilter($_POST['changelog'], 'changelog');
    $query['date'] = $date;
    //copie des fichiers
    foreach ($filesmv as $value) {
        if (!is_file($value['path'])) {
            if (!is_dir($value['dir'])) {
                if (!mkdir($value['dir'], 0755, true)) {
                    trigger_error('mkdirfail');
                    return 'copyfail';
                }
                if (!rename($value['file'], $value['path'])) {
                    trigger_error('copyfail');
                    return 'copyfail';
                }
            }
        }
    }
    if ($new_project) {
        $return[$tstamp] = $query;
        return $return;
    }
    try {
        $db->update(array('_id' => new MongoID($id)), array('$set' => array('files.' . $tstamp => $query)), array('safe' => true, 'upsert' => true));
    } catch (MongoCursorException $e) {
        trigger_error("Insert failed " . $e->getMessage());
        return 'db_error';
    }
    notify_users($id, $projectname, $query['version'], $query['changelog']);
    return 'fileadded';
}
Ejemplo n.º 2
0
    Database::get()->query("UPDATE forum_topic SET topic_time = ?t,
                    num_replies = num_replies+1,
                    last_post_id = ?d
		WHERE id = ?d AND forum_id = ?d", $time, $this_post, $topic, $forum_id);
    $result = Database::get()->query("UPDATE forum SET num_posts = num_posts+1,
                    last_post_id = ?d
		WHERE id = ?d
                    AND course_id = ?d", $this_post, $forum_id, $course_id);
    if (!$result) {
        $tool_content .= $langErrorUpadatePostCount;
        draw($tool_content, 2, null, $head_content);
        exit();
    }

    $subject = Database::get()->querySingle('SELECT title FROM forum_topic WHERE id = ?d', $topic)->title;
    notify_users($forum_id, $forum_name, $topic, $subject, $message, $time);

    $page = "modules/forum/viewtopic.php?course=$course_code&topic=$topic&forum=$forum_id";
    $total_posts = get_total_posts($topic);
    if ($total_posts > $posts_per_page) {
        $page .= '&start=' . ($posts_per_page * intval(($total_posts - 1) / $posts_per_page));
    }
    Session::Messages($langStored, 'alert-success');
    redirect_to_home_page($page);
} else {
    // Topic review
    $tool_content .= action_bar(array(
                array('title' => $langBack,
                    'url' => "viewtopic.php?course=$course_code&topic=$topic&forum=$forum_id",
                    'icon' => 'fa-reply',
                    'level' => 'primary-label')
Ejemplo n.º 3
0
         } else {
             $create_user = "";
         }
     }
     $havedata = 0;
 }
 if ($havedata) {
     $title = db_escape($title);
     $abstract = db_escape($abstract);
     $contents = db_escape($contents);
     $create_date = time();
     $create_user = db_escape($create_user);
     db_query("INSERT INTO article VALUES(NULL," . "{$is_published},'{$title}','{$abstract}','{$contents}'," . "{$create_date},'{$create_user}',{$create_date},'{$create_user}')");
     $id = db_insert_id();
     if (!$is_published) {
         notify_users($id);
     }
     header("Location: {$PHP_SELF}?L{$id}{$options}");
     break;
 }
 html_header("Submit Article");
 html_start_links(1);
 html_link("Return to Articles", "{$PHP_SELF}?L{$options}");
 html_end_links();
 if ($REQUEST_METHOD == "POST") {
     print "<p><b>Error:</b> Please fill in the fields marked in " . "<b><font color='red'>bold red</font></b> below and resubmit " . "your article.</p>\n";
     $hstart = "<font color='red'>";
     $hend = "</font>";
 } else {
     print "<p>Please use this form to post announcements, how-to's, " . "examples, and case studies showing how you use {$PROJECT_NAME}. " . "We will proofread your article, and if we determine it is " . "appropriate for the site, we will make the article public " . "on the site. <i>Thank you</i> for supporting {$PROJECT_NAME}!</p>\n";
     $hstart = "";
Ejemplo n.º 4
0
         $outfile = fopen("strfiles/{$id}/{$name}", "wb");
         if (!$outfile) {
             html_header("Error");
             print "<p><b>Error!</b> Unable to save file attachment!</p>\n";
             html_footer();
             exit;
         }
         while ($data = fread($infile, 8192)) {
             fwrite($outfile, $data);
         }
         fclose($infile);
         fclose($outfile);
         db_query("INSERT INTO strfile VALUES(NULL,{$id},1,'{$tname}'," . "{$time},'{$temail}')");
     }
     header("Location: {$PHP_SELF}?L{$id}{$options}");
     notify_users($id, "created", "{$contents}\n\n");
 } else {
     html_header("Submit Bug or Feature Request");
     html_start_links(1);
     html_link("Return to Bugs &amp; Features", "{$PHP_SELF}?L{$options}");
     html_end_links();
     if ($REQUEST_METHOD == "POST") {
         print "<p><b>Error:</b> Please fill in the fields marked " . "<span class='invalid'>like this</span> below and resubmit " . "your trouble report.</p>\n";
         $hstart = "<span class='invalid'>";
         $hend = "</span>";
     } else {
         print "<p>Please use this form to report all bugs and request " . "features in the {$PROJECT_NAME} software. Be sure to include " . "the operating system, compiler, sample programs and/or " . "files, and any other information you can about your " . "problem. <i>Thank you</i> for helping us to improve " . "{$PROJECT_NAME}!</p>\n";
         $hstart = "";
         $hend = "";
         $recent = time() - 90 * 86400;
         $result = db_query("SELECT master_id, " . "count(master_id) AS count FROM str " . "WHERE master_id > 0 AND modify_date > {$recent} " . "GROUP BY master_id " . "ORDER BY count DESC, modify_date DESC");