function add_bug($post, $id) { $conf = configurations(); if (!count($post)) { return null; } if (!strlen($post['title']) || !strlen($post['version']) || $post['version'] == 'false' || $post['osarch'] == 'false' || !strlen($post['bugdescription']) || is_array($post['title']) || is_array($post['version']) || is_array($post['bugdescription'])) { $_SESSION['post'] = $_POST; return 'fieldmissing'; } $version = explode('!!!!', $post['version']); if (is_null(check_projects(array('_id' => new MongoID($id), 'files.' . $version[0] . '.version' => base64_decode($version[1]))))) { return 'attack'; } $osarch = explode('!!!!', $post['osarch']); if (!in_array($osarch[0], $conf['os']) || !in_array($osarch[1], $conf['arch'])) { return 'attack'; } //vérifie si le bug n'aurait pas déjà été posté $check = list_bugs(array('project' => $id, 'title' => $post['title']), true); if (!is_null($check)) { return array('bugexist', $check['_id']); } //ajoute le bug dans la db $status_array = array_reverse(array_merge($conf['bugs']['Open'], $conf['bugs']['Closed']), false); $con = new Mongo(); $db = $con->{$conf}['base']->{$conf}['bug']; $dbinc = $con->{$conf}['base']->{$conf}['inc']; try { if (is_null($dbinc->findOne(array('_id' => $conf['bug'])))) { $dbinc->insert(array('_id' => $conf['bug'], '#' => 0)); } $inc = $con->{$conf}['base']->command(array('findandmodify' => $conf['inc'], 'query' => array('_id' => $conf['bug']), 'update' => array('$inc' => array('#' => 1)), 'new' => true, 'upsert' => true)); $mongoid = new MongoId(); $db->insert(array('_id' => $mongoid, 'title' => $post['title'], 'userid' => $_SESSION['db_data']['_id'], 'projectid' => $id, 'version' => base64_decode($version[1]), 'status' => $conf['bugs']['Open'][0], 'descript' => $post['bugdescription'], 'os' => $osarch[0], 'arch' => $osarch[1], 'date' => new MongoDate(), '#' => $inc['value']['#'], 'comments_inc' => 0, 'sort' => (int) (array_search($conf['bugs']['Open'][0], $status_array) + 1) . str_pad($inc['value']['#'], 6, "0", STR_PAD_LEFT)), array('safe' => true, 'fsync' => true)); } catch (MongoCursorException $e) { trigger_error('Bug Insert failed ' . $e->getMessage()); return 'db_error'; } send_bug_mail($mongoid); return array('bugreported', $mongoid); }
function html5_user_bug($lang, $mod = null) { global $text_cont; if (is_array($mod)) { return redirect($lang, '?action=' . $mod[0] . $mod[1] . '&mod=' . $mod[2]); } elseif (is_string($mod)) { $cb = 'html5_' . $mod; $mod = $cb($lang); } $id = myfilter($_GET['id'], '_id'); $bug = list_bugs(array('_id' => new MongoId($id)), true); if (is_null($bug)) { $cb = 'html5_' . $_SESSION['db_data']['lvl'] . '_project'; return $cb($lang, 'bugerror'); } $author = getvalue(check_user(array('_id' => new MongoId($bug['userid']))), 'user'); if (is_null($author)) { $author = 'Anonymous'; } $project = getvalue(check_projects(array('_id' => new MongoId($bug['projectid']))), 'name'); if (is_null($project)) { $project = $text_cont[92][$lang]; } $html_var = '<div id="message">' . $mod . '</div><div id="bug"><h2>' . $text_cont[88][$lang] . ' #' . $bug['#'] . ' - ' . html($bug['title']) . '</h2> <div id="bug_date">' . date('d M Y', $bug['date']->sec) . '</div> <div id="bug_sender">' . $text_cont[89][$lang] . ' ' . html($author) . '</div> <div id="bug_project"><a href="?action=project&project_id=' . $bug['projectid'] . '">' . html($project) . '</a></div> <div id="bug_status">' . $text_cont[84][$lang] . ': <span class="status ' . $bug['status'] . '">' . $bug['status'] . '</span></div> <div id="bug_version">' . $text_cont[49][$lang] . ': ' . html($bug['version']) . ' - ' . $text_cont[100][$lang] . ' ' . $bug['os'] . ' ' . $bug['arch'] . '</div> <div id="bug_content">' . nl2br(html($bug['descript'])) . '</div></div>'; //comments $html_var .= list_bugs_comments($lang, $bug['comments']) . '<div id="bug_comments_box"><form id="comment" action="?action=bug&id=' . $id . '" method="post"> <textarea placeholder="' . $text_cont[95][$lang] . '" name="comment_bug"></textarea> <input type="submit" id="sub_button" value="' . $text_cont[96][$lang] . '" /></form></div></div>'; return $html_var; }