function image_zap($image_id) { $filename = db_getOne("SELECT filename FROM image WHERE id=?", $image_id); db_do("DELETE FROM image WHERE id=?", $image_id); db_commit(); unlink(image_path($filename)); }
function force_login($id) { $_SESSION['user'] = $id; $user = User::getUser($id); $_SESSION['user_level'] = $user->getTheme(); ActivityLog::log('login', $user, false, array()); db_do("INSERT INTO activity_log(user_id, action, whenit) VALUES('" . $user->getID() . "', 'login', NOW())"); return $user; }
function do_split($from_ref, $new_from_ref, $split_pubs, $to_ref) { $actions = array(); if ($new_from_ref != $from_ref) { // rename the source journo db_do("UPDATE journo SET ref=? WHERE ref=?", $new_from_ref, $from_ref); $actions[] = sprintf("Renamed journo %s -> %s", $from_ref, admJournoLink($new_from_ref)); $from_ref = $new_from_ref; } $fromj = db_getRow("SELECT id,ref,prettyname,lastname,firstname,status FROM journo WHERE ref=?", $from_ref); $toj = db_getRow("SELECT id,ref,prettyname,lastname,firstname,status FROM journo WHERE ref=?", $to_ref); if (!$toj) { // need to create new journo (just take a copy of 'from' journo) $toj = $fromj; unset($toj['id']); $toj['ref'] = $to_ref; journoCreate($toj); // TODO: copy journo_alias entries too... $actions[] = sprintf("Created new journo: %s", admJournoLink($to_ref)); } // move articles $orglist = implode(',', $split_pubs); if ($orglist) { $sql = <<<EOD UPDATE journo_attr SET journo_id=? WHERE journo_id=? AND article_id IN ( SELECT a.id FROM (article a INNER JOIN journo_attr attr ON a.id=attr.article_id) WHERE journo_id=? AND a.srcorg IN ({$orglist}) ) EOD; $rows_affected = db_do($sql, $toj['id'], $fromj['id'], $fromj['id']); $actions[] = sprintf("reassigned %d articles from %s to %s", $rows_affected, $from_ref, $to_ref); } // leave all other data attached to from_ journo (links, email etc) // Clear the htmlcache for the to and from journos db_do("DELETE FROM htmlcache WHERE name=?", 'j' . $fromj['id']); db_do("DELETE FROM htmlcache WHERE name=?", 'j' . $toj['id']); db_commit(); return $actions; }
case "disapprove_otherarticle": DisapproveOtherArticle($journo_id, get_http_var('otherarticle_id')); EmitJourno($journo_id); break; case "update_admin_notes": $admin_notes = get_http_var('admin_notes'); db_do("UPDATE journo SET admin_notes=? WHERE id=?", $admin_notes, $journo_id); db_commit(); EmitActionMsg("Admin notes changed\n"); EmitJourno($journo_id); break; case "update_admin_tags": $admin_tags = strtolower(get_http_var('admin_tags')); $admin_tags = preg_replace("/[^a-z0-9_]/", " ", $admin_tags); $admin_tags = preg_replace('/\\s+/', " ", $admin_tags); db_do("UPDATE journo SET admin_tags=? WHERE id=?", $admin_tags, $journo_id); db_commit(); EmitActionMsg("Admin tags changed\n"); EmitJourno($journo_id); break; default: if ($journo_id) { EmitJourno($journo_id); } else { print "<h2>Journalists</h2>\n"; EmitJournoFilterForm(); } break; } admPageFooter(); /********************************/
function perform($action) { if ($action == 'delete') { $this->state = 'delete_requested'; } elseif ($action == 'confirm_delete') { //ZAP! db_do("DELETE FROM journo_weblink WHERE id=?", $this->id); db_commit(); $this->state = 'deleted'; } else { if ($action == 'edit') { $this->state = 'editing'; } else { if ($action == 'update') { // update the db to reflect the changes /* db_do( "UPDATE journo_other_articles SET url=?, title=?, pubdate=?, publication=? WHERE id=?", $this->url, $this->title, $this->pubdate->format(DateTime::ISO8601), $this->publication, $this->id ); db_commit(); */ // back to non-editing mode $this->state = ''; } else { if ($action == 'approve') { $this->approved = TRUE; db_do("UPDATE journo_weblink SET approved=? WHERE id=?", $this->approved, $this->id); db_commit(); } else { if ($action == 'unapprove') { $this->approved = FALSE; db_do("UPDATE journo_weblink SET approved=? WHERE id=?", $this->approved, $this->id); db_commit(); } } } } } }
function handle_pingback($method, $params, $extra) { list($sourceURI, $targetURI) = $params; // fetch the source URI to verify that the source does indeed link to the target $html = file_get_contents($sourceURI); if ($html === FALSE) { CRAPLOG("0x10\n"); return 0x10; // "The source URI does not exist." } // cheesy conversion to utf-8 $html = mb_convert_encoding($html, 'UTF-8', mb_detect_encoding($html, 'UTF-8, ISO-8859-1, windows-1252', true)); $html = html_entity_decode($html, ENT_COMPAT, 'UTF-8'); if (strpos($html, $targetURI) === FALSE) { CRAPLOG("0x11\n"); return 0x11; // "The source URI does not contain a link to the target URI, and so cannot be used as a source." } // check URL, try and extract journo ref $bits = crack_url($targetURI); $path = $bits['path']; $m = array(); $ref = null; if (preg_match("%([a-zA-Z0-9]+-[-a-zA-Z0-9]+)/?%", $path, $m)) { $ref = $m[1]; } if ($ref === null) { CRAPLOG("0x21\n"); return 0x21; // "The specified target URI cannot be used as a target." } // valid journo? $journo = db_getRow("SELECT * FROM journo WHERE ref=? AND status='a'", $ref); if ($journo === null) { CRAPLOG("0x21 (invalid journo)\n"); return 0x21; // "The specified target URI cannot be used as a target." } // try and extract title to use as description $desc = $sourceURI; $m = array(); if (preg_match('!<title>(.*?)</title>!i', $html, $m)) { $desc = $m[1]; $desc = preg_replace('/\\s+/', ' ', $desc); } // already got this pingback? if (db_getOne("SELECT id FROM journo_weblink WHERE journo_id=? AND url=? AND approved=true", $journo['id'], $sourceURI)) { CRAPLOG("0x30\n"); return 0x30; // "The pingback has already been registered." } // OK. time to add it! $sql = <<<EOT INSERT INTO journo_weblink (journo_id, url, description, approved, kind, rank) VALUES ( ?,?,?,true,'pingback',500) EOT; db_do($sql, $journo['id'], $sourceURI, $desc); db_commit(); CRAPLOG("added.\n"); return "Ping registered - thanks"; }
function addUser($newUser) { $username = $newUser['username']; $domainId = $newUser['domainId']; $pass = $newUser['pass']; $repPass = $newUser['repPass']; $name = $newUser['name']; $active = $newUser['active']; $errors = array(); $foundError = FALSE; if (!$username) { $foundError = TRUE; $errors['username'] = '******'; } if (!$domainId) { $foundError = TRUE; $errors['domain'] = 'This field is required'; } if (!$pass) { $foundError = TRUE; $errors['password'] = '******'; } if (!$repPass) { $foundError = TRUE; $errors['reppassword'] = '******'; } if (!$active) { $foundError = TRUE; $errors['active'] = 'This field is required'; } if ($foundError) { print json_encode(array('success' => false, 'errors' => $errors)); return; } $username = strtolower($username); if (!validUserName($username)) { $foundError = TRUE; $errors['username'] = '******'; } $domain = getDomain($domainId); if (!$domain) { $foundError = TRUE; $errors['domain'] = 'Invalid domain'; } if ($foundError) { print json_encode(array('success' => false, 'errors' => $errors)); return; } $email = $username . '@' . $domain; $errors = array(); $foundError = FALSE; if (userExists($email) || localForwardExists($email)) { $foundError = TRUE; $errors['username'] = '******'; } if (strlen($pass) < 8) { $foundError = TRUE; $errors['password'] = '******'; } if ($pass != $repPass) { $foundError = TRUE; $errors['reppassword'] = '******'; } $adminDomains = getAdminDomains(); if (!in_array($domain, $adminDomains)) { $foundError = TRUE; $errors['domain'] = 'Permission denied on domain: ' . $domain; } // TODO add password complexity requirements here if ($foundError) { print json_encode(array('success' => false, 'errors' => $errors)); return; } if (!$name) { $name = ''; } if ($active == 'true') { $active = 't'; } else { $active = 'f'; } $sql = 'INSERT INTO virtual_users (' . ' username,' . ' domain_id,' . ' password,' . ' role_id,' . ' description,' . ' active' . ' ) VALUES (?, ?, CRYPT(?, GEN_SALT(\'bf\', 8)), ?, ?, ?)'; $params = array($username, $domainId, $pass, getRoleId('user'), $name, $active); beginTransaction(); $rs = db_do($sql, $params); if (!$rs) { cancelTransaction(); print json_encode(array('success' => false, 'errors' => array('username' => 'Unknown Error'))); return; } $userId = getUserId($email); if (!$userId) { cancelTransaction(); print json_encode(array('success' => false, 'errors' => array('username' => 'Unknown Error'))); return; } $alias = array('username' => $username, 'domain_id' => $domainId, 'destination' => $email, 'active' => $active); $aliasId = db_insert('virtual_aliases', $alias, 'alias_id'); if (!$aliasId) { cancelTransaction(); print json_encode(array('success' => false, 'errors' => array('username' => 'Unknown Error'))); return; } $alias['active'] = $active; $alias['destination'] = $email . '@autoreply.' . $domain; $aliasId = db_insert('virtual_aliases', $alias, 'alias_id'); if (!$aliasId) { cancelTransaction(); print json_encode(array('success' => false, 'errors' => array('username' => 'Unknown Error'))); return; } endTransaction(); print json_encode(array('success' => true)); }
/* there is cached data - yay! */ $data = json_decode($cached_json, true); if ($can_edit_page && $journo['modified'] == 't') { /* journo is logged in and the page is out of date... * update the cached data with some fresh quick-n-nasty data * (which covers most of what a journo might be editing via their profile page, say) */ $old_quick_n_nasty = $data['quick_n_nasty']; $newdata = journo_collectData($journo, true); $data = array_merge($data, $newdata); /* if there was non-quick-n-nasty data there, this makes sure it'll still be used in the template */ $data['quick_n_nasty'] = $old_quick_n_nasty; /* store it in the cache for other users to enjoy too :-) */ $updated_json = json_encode($data); db_do("DELETE FROM htmlcache WHERE name=?", $cacheid); db_do("INSERT INTO htmlcache (name,content) VALUES(?,?)", $cacheid, $updated_json); db_commit(); } } } // HACK: // fields that we've recently added, which might not be in cached versions if (!array_key_exists('num_alerts', $data)) { $data['num_alerts'] = 0; } if (!array_key_exists('admired_by', $data)) { $data['admired_by'] = array(); } // some stuff we don't cache: $data['can_edit_page'] = $can_edit_page; // recent editing changes (from the eventlog) - would be fine to cache this list, but we'd
function save() { db_do("UPDATE article_error SET url=?, reason_code=?, submitted=?, submitted_by=?, article_id=?, expected_journo=? WHERE id=?", $this->url, $this->status, $this->when_submitted, is_null($this->submitted_by) ? null : $this->submitted_by->id, is_null($this->article) ? null : $this->article->id, is_null($this->expected_journo) ? null : $this->expected_journo->id, $this->id); }
function handleSubmit() { $email = get_http_var('email'); $phone = get_http_var('phone'); $address = get_http_var('address'); $twitter = get_http_var('twitter'); $twitter = preg_replace("/^@+/", "", $twitter); // address db_do("DELETE FROM journo_address WHERE journo_id=?", $this->journo['id']); if ($address) { db_do("INSERT INTO journo_address (journo_id,address) VALUES (?,?)", $this->journo['id'], $address); } // phone db_do("DELETE FROM journo_phone WHERE journo_id=?", $this->journo['id']); if ($phone) { db_do("INSERT INTO journo_phone (journo_id,phone_number) VALUES (?,?)", $this->journo['id'], $phone); } // email db_do("DELETE FROM journo_email WHERE journo_id=? AND srctype=''", $this->journo['id']); if ($email) { db_do("INSERT INTO journo_email (journo_id,email,srctype,srcurl,approved) VALUES (?,?,?,?,?)", $this->journo['id'], $email, '', '', TRUE); } // twitter db_do("DELETE FROM journo_weblink WHERE journo_id=? AND kind='twitter'", $this->journo['id']); if ($twitter) { $twitter_url = 'http://twitter.com/' . $twitter; $twitter_desc = $this->journo['prettyname'] . ' on Twitter'; db_do("INSERT INTO journo_weblink (journo_id,url,description,approved,kind) VALUES (?,?,?,true,'twitter')", $this->journo['id'], $twitter_url, $twitter_desc); } db_commit(); eventlog_Add('modify-contact', $this->journo['id']); }
function genericStoreItem($tablename, $fieldnames, &$item) { if ($item['id']) { /* update existing entry */ $frags = array(); $params = array(); foreach ($fieldnames as $f) { $frags[] = "{$f}=?"; $params[] = $item[$f]; } /* note, restrict by journo id to stop people hijacking others entries! */ $sql = "UPDATE {$tablename} SET " . implode(',', $frags) . " WHERE id=? AND journo_id=?"; $params[] = $item['id']; $params[] = $this->journo['id']; db_do($sql, $params); eventlog_Add("modify-{$this->pageName}", $this->journo['id'], $item); } else { /* insert new entry */ $frags = array('?'); $params = array($this->journo['id']); foreach ($fieldnames as $f) { $frags[] = "?"; $params[] = $item[$f]; } $sql = "INSERT INTO {$tablename} (journo_id," . implode(",", $fieldnames) . ") " . "VALUES (" . implode(',', $frags) . ")"; db_do($sql, $params); $item['id'] = db_getOne("SELECT lastval()"); eventlog_Add("add-{$this->pageName}", $this->journo['id'], $item); } db_commit(); return $item['id']; }
function do_reallychangeemail() { $person_id = get_http_var("person_id"); $person = db_getRow("SELECT * FROM person WHERE id=?", get_http_var('person_id')); $old_email = $person['email']; $new_email = get_http_var("new_email"); db_do("UPDATE person SET email=? WHERE id=?", $new_email, $person_id); db_commit(); ?> <div class="action_summary"> Changed email address<br/>from: <code><?php echo $old_email; ?> <br/></code> to: <code><?php echo $new_email; ?> </code> </div> <?php emit_details($person_id); }
function save() { // NOTE: expects member fk objects to already have been saved if ($this->pk()) { // update existing entry $frags = array(); $params = array(); foreach ($this->fields as $f => $def) { if (!$def['pk']) { switch ($def['type']) { case 'fk': $frags[] = "{$f}=?"; $params[] = is_null($this->{$f}) ? null : $this->{$f}->pk(); break; case 'datetime': $frags[] = "{$f}=?"; $params[] = $this->{$f} ? $this->{$f} : null; break; default: $frags[] = "{$f}=?"; $params[] = $this->{$f}; break; } } } $sql = "UPDATE {$this->table} SET " . implode(',', $frags) . " WHERE id=?"; $params[] = $this->{$this->pk}; db_do($sql, $params); // eventlog_Add( "modify-{$this->pageName}", $this->journo['id'], $item ); } else { /* insert new entry */ $frags = array(); $params = array(); $insert_fields = array(); foreach ($this->fields as $f => $def) { if (!$def['pk']) { switch ($def['type']) { case 'fk': $insert_fields[] = $f; $frags[] = "?"; $params[] = is_null($this->{$f}) ? null : $this->{$f}->pk(); break; case 'datetime': $insert_fields[] = $f; $frags[] = "?"; $params[] = $this->{$f} ? $this->{$f} : null; break; default: $insert_fields[] = $f; $frags[] = "?"; $params[] = $this->{$f}; break; } } } $sql = "INSERT INTO {$this->table} (" . implode(",", $insert_fields) . ") " . "VALUES (" . implode(',', $frags) . ")"; //print $sql; db_do($sql, $params); $this->{$this->pk} = db_getOne("SELECT lastval()"); // eventlog_Add( "add-{$this->pageName}", $this->journo['id'], $item ); } db_commit(); }
function SetActions($srcids, $val) { $sqlbits = array(); $sqlparams = array($val); foreach ($srcids as $id) { $sqlbits[] = '?'; $sqlparams[] = $id; } $sql = "UPDATE error_articlescrape SET action=? WHERE srcid IN (" . implode(',', $sqlbits) . ")"; $cnt = db_do($sql, $sqlparams); db_commit(); printf("<div class=\"action_summary\">set %d articles to '%s'</div><br />\n", $cnt, $val == 's' ? 'skip' : 'undecided'); }
function create_journo($params) { $f = substr(metaphone($params['firstname']), 0, 4); $l = substr(metaphone($params['lastname']), 0, 4); if (!$f) { $f = ''; } if (!$l) { $l = ''; } db_do("INSERT INTO journo (ref,prettyname,firstname,lastname,status,firstname_metaphone, lastname_metaphone,created) VALUES (?,?,?,?,?,?,?,NOW())", $params['ref'], $params['prettyname'], $params['firstname'], $params['lastname'], 'a', $f, $l); db_commit(); ?> <p>Created new journo: <a href="/<?php echo $params['ref']; ?> "><?php echo $params['ref']; ?> </a> [<a href="/adm/<?php echo $params['ref']; ?> ">admin page</a>]</p> <?php }
function journo_create($fullname) { $fullname = trim($fullname); $fullname = preg_replace('/\\s+/', ' ', $fullname); // collapse spaces // TODO: should deal with name titles/suffixes ("Dr." etc) but not a big deal $ref = toRef($fullname); // special case to deal with one-word names if (strpos($ref, '-') === FALSE) { $ref .= "-1"; } // make sure ref is unique $i = 1; while (db_getOne("SELECT id FROM journo WHERE ref=?", $ref)) { $ref = toRef($fullname) . "-" . $i++; } // work out firstname and lastname $parts = explode(' ', $fullname); $firstname = array_shift($parts); if (is_null($firstname)) { $firstname = ''; } $lastname = array_pop($parts); if (is_null($lastname)) { $lastname = ''; } $sql = <<<EOT INSERT INTO journo (ref,prettyname,firstname,lastname,status,firstname_metaphone,lastname_metaphone,created) VALUES (?,?,?,?,?,?,?,NOW()) EOT; db_do($sql, $ref, $fullname, $firstname, $lastname, 'i', substr(metaphone($firstname), 0, 4), substr(metaphone($lastname), 0, 4)); db_commit(); return db_getRow("SELECT * FROM journo WHERE ref=?", $ref); }
function replacePhoto($p, $is_thumbnail = FALSE) { $new_photo = null; if ($p) { if (is_resource($p) && get_resource_type($p) == 'gd') { $new_photo = image_storeGD($p); } else { // assume it's an uploaded file $new_photo = image_storeUploaded($p); } if ($new_photo) { $new_photo['image_id'] = $new_photo['id']; $new_photo['is_thumbnail'] = $is_thumbnail; unset($new_photo['id']); } } if ($this->photo) { // remove existing one from db db_do("DELETE FROM journo_photo WHERE id=?", $this->photo['id']); db_do("DELETE FROM image WHERE id=?", $this->photo['image_id']); } if ($new_photo) { // put new one in db $new_photo['id'] = db_getOne("select nextval('journo_photo_id_seq' )"); db_do("INSERT INTO journo_photo (journo_id,image_id,is_thumbnail) VALUES (?,?,?)", $this->journo['id'], $new_photo['image_id'], $new_photo['is_thumbnail']); } db_commit(); if ($this->photo) { // db synced - can now zap the old file unlink(image_path($this->photo['filename'])); } // done. $this->photo = $new_photo; }
function _register_error() { $reason = $this->state; assert($reason == 'scrape_failed' || $reason == 'journo_mismatch'); $extra = ''; // could be extra context, in json fmt $art_id = is_null($this->article) ? null : $this->article['id']; $journo_id = is_null($this->journo) ? null : $this->journo['id']; $person = person_if_signed_on(); $person_id = is_null($person) ? null : $person->id(); // uh-oh. queue it up for admin attention db_do("DELETE FROM article_error WHERE url=?", $this->url); db_do("INSERT INTO article_error (url,reason_code,submitted_by,article_id,expected_journo) VALUES (?,?,?,?,?)", $this->url, $reason, $person_id, $art_id, $journo_id); db_commit(); }
function journo_checkActivation($journo_id) { if (journo_countArticles($journo_id) >= OPTION_JL_JOURNO_ACTIVATION_THRESHOLD) { $n = db_do("UPDATE journo SET status='a', modified=true WHERE status='i' AND id=?", $journo_id); db_commit(); if ($n > 0) { return TRUE; } } return FALSE; }
} if ($do_insert) { db_do("INSERT INTO base_object(creator, project, parent, title, created, description) VALUES(" . $user_old_to_new['a' . $row['user_id']] . ", " . $project_old_to_new['a' . $row['project_id']] . ", {$parent}, {$title_id}, '" . $row['posted'] . "', {$body_id})"); $ver_id = mysql_insert_id(); db_do("INSERT INTO obj_static(type, current) VALUES(6, {$ver_id})"); $conversation_old_to_new['a' . $row['id']] = mysql_insert_id(); } } db_do("ALTER TABLE conversation DROP title, DROP body, DROP user_id, DROP posted"); $res = db_do("SELECT * FROM file"); $files_old_to_new = array(); while ($row = mysql_fetch_assoc($res)) { $files_old_to_new['a' . $row['id']] = $row; db_do("UPDATE file SET project_id = '" . $project_old_to_new['a' . $row['project_id']] . "' WHERE id = '" . $row['id'] . "'"); } $res = db_do("SELECT * FROM file_version"); while ($row = mysql_fetch_assoc($res)) { db_do("INSERT INTO obj_string(value) VALUES('" . mysql_real_escape_string($row['shortdesc']) . "')"); $title_id = mysql_insert_id(); db_do("INSERT INTO obj_text(value) VALUES('" . mysql_real_escape_string($row['note']) . "')"); $body_id = mysql_insert_id(); db_do("INSERT INTO base_object(creator, title, created, description, parent) VALUES(" . $user_old_to_new['a' . $row['creator_id']] . ", {$title_id}, '" . $row['created'] . "', {$body_id}, '" . $project_old_to_new['a' . $files_old_to_new['a' . $row['file_id']]['project_id']] . "')"); $ver_id = mysql_insert_id(); db_do("INSERT INTO obj_static(type, current, views) VALUES(7, {$ver_id}, '" . $row['dl_count'] . "')"); } db_do("ALTER TABLE file_version DROP shortdesc, DROP note, DROP creator_id, DROP created, DROP dl_count"); $res = db_do("SELECT * FROM project_user"); while ($row = mysql_fetch_assoc($res)) { db_do("UPDATE project_user SET user_id = '" . $user_old_to_new['a' . $row['user_id']] . "', project_id = '" . $project_old_to_new['a' . $row['project_id']] . "' WHERE id = '" . $row['id'] . "'"); } echo $query_count . " queries\n";
chdir(dirname($_SERVER['SCRIPT_FILENAME'])); require_once "../conf/general"; require_once '../../phplib/db.php'; require_once '../phplib/journo.php'; $q = null; if (sizeof($argv) > 1) { $ref = $argv[1]; if ($ref == '--all') { print "do ALL journos...\n"; $q = db_query("SELECT id,ref,firstname,lastname FROM journo"); } else { print "do single journo...\n"; $q = db_query("SELECT id,ref,firstname,lastname FROM journo WHERE ref=?", $ref); } } else { print "look for journos with missing metaphones...\n"; $q = db_query("SELECT id,ref,firstname,lastname FROM journo WHERE firstname_metaphone='' OR lastname_metaphone=''"); } $cnt = 0; while ($j = db_fetch_array($q)) { $f = metaphone($j['firstname'], 4); $l = metaphone($j['lastname'], 4); print "'{$j['firstname']}', '{$j['lastname']}' ({$j['ref']}): {$f},{$l}\n"; db_do("UPDATE journo SET firstname_metaphone=?, lastname_metaphone=? WHERE id=?", $f, $l, $j['id']); $cnt++; } db_commit(); print "done. set metaphones on {$cnt} journos\n"; ?>
function find_or_create_publication($domain) { $foo = preg_replace("/^www[.]/", "", $domain); $pub_id = db_getOne("SELECT pub_id FROM pub_domain WHERE domain in (?,?) LIMIT 1", $foo, "www.{$foo}"); if (!is_null($pub_id)) { return $pub_id; } // not found, so create a new publication: $shortname = $foo; $prettyname = $foo; $shortname = $foo; $sortname = $foo; $home_url = "http://{$domain}"; $pub_id = db_getOne("INSERT INTO organisation (id,shortname,prettyname,sortname,home_url) VALUES (DEFAULT, ?,?,?,?) RETURNING id", $shortname, $prettyname, $sortname, $home_url); db_do("INSERT INTO pub_domain (pub_id,domain) VALUES (?,?)", $pub_id, $domain); db_do("INSERT INTO pub_alias (pub_id,alias) VALUES (?,?)", $pub_id, $prettyname); return $pub_id; }
function SetBios($email_ids, $val) { $cnt = 0; foreach ($email_ids as $email_id) { $row = db_getRow("SELECT journo_id,approved FROM journo_email WHERE id=?", $email_id); if ($row['approved'] != $val) { db_do("UPDATE journo_email SET approved=? WHERE id=?", $val, $email_id); db_do("DELETE FROM htmlcache WHERE name=?", 'j' . $row['journo_id']); $cnt += 1; } } db_commit(); printf("<p><strong>%s %d email address(es)</strong></p>\n", $val == 't' ? 'approved' : 'unapproved', $cnt); }
function db_update_assoc($table, $assoc, $condition, $persistent = FALSE) { if (empty($assoc) || !is_array($assoc)) { db_error('db_insert_assoc(): Invalid array passed'); return -1; } elseif (empty($condition)) { db_error('db_insert_assoc(): No update condition passed'); return -1; } $sql = "UPDATE {$table} SET "; foreach ($assoc as $key => $value) { if (empty($value) && strlen($value) == 0) { $sql .= "{$key}=NULL, "; } elseif ($value == 'NOW()') { $sql .= "{$key}={$value}, "; } else { $sql .= "{$key}='" . db_escape($value) . "', "; } } $sql = rtrim($sql, ', ') . " {$condition}"; return db_do($sql, $persistent); }
function handleRemove() { $id = get_http_var("remove_id"); // include journo id, to stop people zapping other journos entries! db_do("DELETE FROM journo_weblink WHERE id=? AND journo_id=?", $id, $this->journo['id']); db_commit(); eventlog_Add('remove-weblinks', $this->journo['id']); }
require_once '../../phplib/db.php'; require_once '../../phplib/person.php'; require_once '../../phplib/importparams.php'; $r = array('reason_web' => "Subscribe to the journalisted weekly digest", 'reason_email' => "Subscribe to the journalisted weekly digest", 'reason_email_subject' => "Subscribe to the journalisted weekly digest"); $P = person_signon($r); $action = get_http_var('action'); page_header("Weekly digest"); $info_msg = null; if ($action == 'subscribe') { db_do("DELETE FROM person_receives_newsletter WHERE person_id=?", $P->id); db_do("INSERT INTO person_receives_newsletter (person_id) VALUES (?)", $P->id); db_commit(); $info_msg = "You have been subscribed to the weekly digest."; } if ($action == 'unsubscribe') { db_do("DELETE FROM person_receives_newsletter WHERE person_id=?", $P->id); db_commit(); $info_msg = "You have been unsubscribed from the weekly digest."; } $subscribed = FALSE; if (!is_null(db_getOne("SELECT person_id FROM person_receives_newsletter WHERE person_id=?", $P->id))) { $subscribed = TRUE; } ?> <div class="main"> <?php if ($info_msg) { ?> <div class="infomessage">
function cache_clear($cacheid) { db_do("DELETE FROM htmlcache WHERE name=?", $cacheid); db_commit(); }
echo "<br>The start date must be before the end date {$start} >= {$end}."; exit; } echo "<h3>Export Stats</h3>\nBetween {$start} and {$end}<br>\n<table style='border: 1px solid black; border-collapse:collapse;'>\n\t<tr>\n\t\t<th>Service</th>\n\t\t<th>Export</th>\n\t\t<th colspan='3'>Full</th>\n\t\t<th colspan='3'>Partial</th>\n\t\t<th> Totals </th>\n\t</tr>\n"; $sql = "SELECT serviceid, exportset,\nsum(if(source='t', tally-loadpartial-loademptypart-loadempty,0)) as sumfull,\nsum(if(source='o', tally-loadpartial-loademptypart-loadempty,0)) as sumodisfull,\nsum(if(source='t', loadpartial,0)) as sumpart,\nsum(if(source='o', loadpartial,0)) as sumodispart\nFROM portal_stats.tallies\nWHERE exportdate BETWEEN '{$start}' AND '{$end}'\nGROUP BY serviceid, exportset"; //echo $sql; /*$sql="SELECT serviceid, exportset, sum(if(loadagent='odis' and not loadpartial,1,0)) as sumodisfull, sum(if(loadagent!='odis' and not loadpartial,1,0)) as sumfull, sum(if(loadagent='odis' and loadpartial,1,0)) as sumodispart, sum(if(loadagent!='odis' and loadpartial,1,0)) as sumpart FROM loader07.records WHERE exporttime BETWEEN '{$start}' AND '{$end}' and loadempty='0' GROUP BY serviceid, exportset";*/ //echo $sql; $dbr = db_do($sql); $f_fonetotal = $f_odistotal = $p_fonetotal = $p_odistotal = $rowcount = 0; $rowcount = 0; $totalfull = 0; $totalodisfull = 0; $totalpart = 0; $totalodispart = 0; $lastclient = ''; $headonnext = true; foreach ($dbr as $record) { $fullline = $record['sumfull'] + $record['sumodisfull']; $partline = $record['sumpart'] + $record['sumodispart']; if (($totalline = $fullline + $partline) > 0) { $totalfull += $record['sumfull']; $totalodisfull += $record['sumodisfull']; $totalpart += $record['sumpart'];
function newsDelete($post) { db_do("DELETE FROM news WHERE id=?", $post['id']); db_commit(); ?> <div class="action_summary">Deleted '<?php echo $post['title']; ?> '</div> <?php }
function do_DenyClaim() { $person_id = get_http_var('person_id'); $journo_id = get_http_var('journo_id'); $person = db_getRow("SELECT * FROM person WHERE id=?", $person_id); $journo = db_getRow("SELECT * FROM journo WHERE id=?", $journo_id); db_do("UPDATE person_permission SET permission='claim_denied' WHERE person_id=? AND journo_id=? AND permission='claimed'", $person_id, $journo_id); db_commit(); ?> <div class="action_summary"> <p>Denied claim on <?php echo journo_link($journo); ?> by <?php echo $person['email']; ?> </p> </div> <?php }