require_once 'MDB2.php'; require_once("logger.inc.php"); function getMysqlConnection() { $mysql_host = "mysql5.vmk.zhdk.ch"; $mysql_user = "kunstfreiheit"; $mysql_pass = "kalakul11_X"; $mysql_db = "kunstfreiheit"; $dsn = "mysql://$mysql_user:$mysql_pass@$mysql_host/$mysql_db"; $options = array( 'debug' => 2, 'result_buffering' => false, ); $mdb2 =& MDB2::singleton($dsn, $options); if (PEAR::isError($mdb2)) { log_error("No connection could be established", __FILE__ ); log_error("MDB2 said: " . $mdb2->getMessage(), __FILE__ ); return false; } else { return $mdb2; } } function getSignatures($sortorder = "la") { /* // not necessary at the moment since offset/limit is handled // by the Pager if( is_int($offset) && $offset > 0) { } else { $offset = 0; } if( is_int($max) && $max > 0 && $max < 1000 ) { } else { $max = 30; } */ $db = getMysqlConnection(); // yes, i should replace this by a switch statement if( $sortorder == "la" ) { $order = " ORDER BY lastname ASC"; } elseif( $sortorder == "fa" ) { $order = " ORDER BY firstname ASC"; } elseif( $sortorder == "ld" ) { $order = " ORDER BY lastname DESC"; } elseif( $sortorder == "fd" ) { $order = " ORDER BY firstname DESC"; } elseif( $sortorder == "ta" ) { $order = " ORDER BY timestamp ASC"; } elseif( $sortorder == "td" ) { $order = " ORDER BY timestamp DESC"; } elseif( $sortorder == "oa" ) { $order = " ORDER BY occupation ASC"; } elseif( $sortorder == "ia" ) { $order = " ORDER BY institution ASC"; } else { $order = " ORDER BY lastname ASC"; } if($db) { // Proceed with a query... $res =& $db->query("SELECT DISTINCT firstname, lastname, occupation, institution, place, email, id FROM petition_signatures $order"); // Always check that result is not an error if (PEAR::isError($res)) { log_error("Couldn't get signatures, error was: ", __FILE__ ); log_error($res->getMessage(), __FILE__ ); return false; } $sigs = $res->fetchAll(); return $sigs; $res->free(); } else { return false; } } function getEmails() { $db = getMysqlConnection(); if($db) { // Proceed with a query... $res =& $db->query("SELECT DISTINCT email FROM petition_signatures where email is not null and email not like '' order by email"); // Always check that result is not an error if (PEAR::isError($res)) { log_error("Couldn't get e-mails, error was: ", __FILE__ ); log_error($res->getMessage(), __FILE__ ); return false; } $emails = $res->fetchAll(); return $emails; $res->free(); } else { return false; } } function addSignature($firstname, $lastname, $occupation = " ", $institution = " ", $place = " ", $email = " ") { // works $db = getMysqlConnection(); $table_name = 'petition_signatures'; $fields_values = array( 'firstname' => $firstname, 'lastname' => $lastname, 'occupation' => $occupation, 'institution' => $institution, 'place' => $place, 'email' => $email ); $types = array('text', 'text', 'text', 'text', 'text', 'text'); #log_error("adding $firstname, $lastname, $occupation, $institution, $place, $email"); $db->loadModule('Extended'); $affectedRows = $db->extended->autoExecute($table_name, $fields_values, MDB2_AUTOQUERY_INSERT, null, $types); if (PEAR::isError($res)) { log_error("Could not add signature, " . $res->getMessage(), __FILE__); return false; } else { return true; } } function getSignature($id = 0) { $db = getMysqlConnection(); $res = $db->query("SELECT firstname, lastname, occupation, institution, place, email FROM petition_signatures where id = $id"); if(!PEAR::isError($res)) { $sig = $res->fetchRow(MDB2_FETCHMODE_ASSOC); return $sig; } else { return false; } } function deleteSignature($id = 0) { $db = getMysqlConnection(); $res = $db->query("delete FROM petition_signatures where id = $id"); if(!PEAR::isError($res)) { return true; } else { return false; } } ?> |