function run(Contact $user, $qreq, $ssel) { global $Conf, $Opt; // maybe download preferences for someone else $Rev = $user; if (($cid = cvtint($qreq->reviewer)) > 0 && $user->privChair) { if (!($Rev = Contact::find_by_id($cid))) { return Conf::msg_error("No such reviewer"); } } if (!$Rev->isPC) { return self::EPERM; } $q = $Conf->paperQuery($Rev, array("paperId" => $ssel->selection(), "topics" => 1, "reviewerPreference" => 1)); $result = Dbl::qe_raw($q); $texts = array(); while ($prow = PaperInfo::fetch($result, $Rev)) { $t = $prow->paperId . "," . CsvGenerator::quote($prow->title); if ($prow->conflictType > 0) { $t .= ",conflict"; } else { $t .= "," . unparse_preference($prow); } $t .= "\n"; if ($this->extended) { if ($Rev->can_view_authors($prow, false)) { $t .= prefix_word_wrap("# Authors: ", $prow->pretty_text_author_list(), "# "); } $t .= prefix_word_wrap("# Abstract: ", rtrim($prow->abstract), "# "); if ($prow->topicIds != "") { $t .= prefix_word_wrap("# Topics: ", $prow->unparse_topics_text(), "# "); } $t .= "\n"; } defappend($texts[$prow->paperId], $t); } downloadCSV(join("", $ssel->reorder($texts)), ["paper", "title", "preference"], "revprefs"); }
function parseBulkFile($text, $filename) { global $Conf; $text = cleannl($text); if (!is_valid_utf8($text)) { $text = windows_1252_to_utf8($text); } $filename = $filename ? "{$filename}:" : "line "; $success = array(); if (!preg_match('/\\A[^\\r\\n]*(?:,|\\A)(?:user|email)(?:[,\\r\\n]|\\z)/', $text) && !preg_match('/\\A[^\\r\\n]*,[^\\r\\n]*,/', $text)) { $tarr = CsvParser::split_lines($text); foreach ($tarr as &$t) { if (($t = trim($t)) && $t[0] !== "#" && $t[0] !== "%") { $t = CsvGenerator::quote($t); } $t .= "\n"; } unset($t); $text = join("", $tarr); } $csv = new CsvParser($text); $csv->set_comment_chars("#%"); $line = $csv->next(); if ($line && (array_search("email", $line) !== false || array_search("user", $line) !== false)) { $csv->set_header($line); } else { $csv->set_header(array("user")); $csv->unshift($line); } $cj_template = (object) array(); $topic_revmap = array(); foreach ($Conf->topic_map() as $id => $name) { $topic_revmap[strtolower($name)] = $id; } $unknown_topics = array(); $errors = array(); while (($line = $csv->next()) !== false) { $cj = clone $cj_template; foreach ($line as $k => $v) { $cj->{$k} = $v; } foreach (array("firstname" => "firstName", "first" => "firstName", "lastname" => "lastName", "last" => "lastName", "fullname" => "name", "fullName" => "name", "voice" => "voicePhoneNumber", "phone" => "voicePhoneNumber", "address1" => "addressLine1", "province" => "state", "region" => "state", "address2" => "addressLine2", "postalcode" => "zipCode", "zip" => "zipCode", "tags" => "contactTags") as $k => $x) { if (isset($cj->{$k}) && !isset($cj->{$x})) { $cj->{$x} = $cj->{$k}; } } // thou shalt not set passwords by bulk update unset($cj->password, $cj->password_plaintext, $cj->new_password); if (isset($cj->name) && !isset($cj->firstName) && !isset($cj->lastName)) { list($cj->firstName, $cj->lastName) = Text::split_name($cj->name); } if (count($topic_revmap)) { foreach (array_keys($line) as $k) { if (preg_match('/^topic:\\s*(.*?)\\s*$/i', $k, $m)) { if (($ti = @$topic_revmap[strtolower($m[1])]) !== null) { $x = $line[$k]; if (strtolower($x) === "low") { $x = -2; } else { if (strtolower($x) === "high") { $x = 4; } else { if (!is_numeric($x)) { $x = 0; } } } if (!@$cj->topics) { $cj->topics = (object) array(); } $cj->topics->{$ti} = $x; } else { $unknown_topics[$m[1]] = true; } } } } $cj->id = "new"; $ustatus = new UserStatus(array("send_email" => true, "no_deprivilege_self" => true)); if ($saved_user = save_user($cj, $ustatus, null, true)) { $success[] = "<a href=\"" . hoturl("profile", "u=" . urlencode($saved_user->email)) . "\">" . Text::user_html_nolink($saved_user) . "</a>"; } foreach ($ustatus->error_messages() as $e) { $errors[] = "<span class='lineno'>" . $filename . $csv->lineno() . ":</span> " . $e; } } if (count($unknown_topics)) { $errors[] = "There were unrecognized topics (" . htmlspecialchars(commajoin($unknown_topics)) . ")."; } if (count($success) == 1) { $successMsg = "Saved account " . $success[0] . "."; } else { if (count($success)) { $successMsg = "Saved " . plural($success, "account") . ": " . commajoin($success) . "."; } } if (count($errors)) { $errorMsg = "<div class='parseerr'><p>" . join("</p>\n<p>", $errors) . "</p></div>"; } if (count($success) && count($errors)) { $Conf->confirmMsg($successMsg . "<br />{$errorMsg}"); } else { if (count($success)) { $Conf->confirmMsg($successMsg); } else { if (count($errors)) { Conf::msg_error($errorMsg); } else { $Conf->warnMsg("Nothing to do."); } } } return count($errors) == 0; }
function run(Contact $user, $qreq, $ssel) { global $Conf; $result = Dbl::qe_raw($Conf->paperQuery($user, ["paperId" => $ssel->selection()])); $papers = []; while ($prow = PaperInfo::fetch($result, $user)) { if ($user->can_view_pdf($prow)) { $papers[$prow->paperId] = $prow; } } $csvg = downloadCSV(false, ["paper", "title", "pages", "format"], "formatcheck"); echo $csvg->headerline; $format = $Conf->setting_data("sub_banal", ""); foreach ($ssel->reorder($papers) as $prow) { $pages = "?"; if ($prow->mimetype == "application/pdf") { $cf = new CheckFormat(); $dtype = $prow->finalPaperStorageId ? DTYPE_FINAL : DTYPE_SUBMISSION; if ($cf->analyzePaper($prow->paperId, $dtype, $format)) { $format = array(); foreach (CheckFormat::$error_types as $en => $etxt) { if ($cf->errors & $en) { $format[] = $etxt; } } $format = empty($format) ? "ok" : join(",", $format); $pages = $cf->pages; } else { $format = "error"; } } else { $format = "notpdf"; } echo $prow->paperId, ",", CsvGenerator::quote($prow->title), ",", $pages, ",", CsvGenerator::quote($format), "\n"; ob_flush(); flush(); } exit; }
static function settags_api($user, $qreq, $prow) { global $Conf; if ($qreq->cancelsettags) { json_exit(["ok" => true]); } if ($prow && !$user->can_view_paper($prow)) { json_exit(["ok" => false, "error" => "No such paper."]); } // save tags using assigner $x = array("paper,action,tag"); if ($prow) { if (isset($qreq->tags)) { $x[] = "{$prow->paperId},tag,all#clear"; foreach (TagInfo::split($qreq->tags) as $t) { $x[] = "{$prow->paperId},tag," . CsvGenerator::quote($t); } } foreach (TagInfo::split((string) $qreq->addtags) as $t) { $x[] = "{$prow->paperId},tag," . CsvGenerator::quote($t); } foreach (TagInfo::split((string) $qreq->deltags) as $t) { $x[] = "{$prow->paperId},tag," . CsvGenerator::quote($t . "#clear"); } } else { if (isset($qreq->tagassignment)) { $pids = []; $pid = -1; foreach (preg_split('/[\\s,]+/', $qreq->tagassignment) as $w) { if ($w !== "" && ctype_digit($w)) { $pid = intval($w); } else { if ($w !== "" && $pid > 0) { $x[] = "{$pid},tag," . CsvGenerator::quote($w); $pids[$pid] = true; } } } } } $assigner = new AssignmentSet($user, $user->is_admin_force()); $assigner->parse(join("\n", $x)); $error = join("<br />", $assigner->errors_html()); $ok = $assigner->execute(); // exit if ($ok && $prow) { $prow->load_tags(); $treport = self::tagreport($user, $prow); if ($treport->warnings) { $Conf->warnMsg(join("<br>", $treport->warnings)); } $taginfo = (object) ["ok" => true, "pid" => $prow->paperId]; $prow->add_tag_info_json($taginfo, $user); json_exit($taginfo, true); } else { if ($ok) { $p = []; $result = Dbl::qe_raw($Conf->paperQuery($user, ["paperId" => array_keys($pids), "tags" => true])); while ($prow = PaperInfo::fetch($result, $user)) { $p[$prow->paperId] = (object) []; $prow->add_tag_info_json($p[$prow->paperId], $user); } json_exit(["ok" => true, "p" => $p]); } else { json_exit(["ok" => false, "error" => $error], true); } } }