/**
  function Save()
  Required parameters :- Parent type, Parent id, Body of report and Reporter id
  @return Report id if data is successfully saved.
 */
 public function save()
 {
     Logger::log("Enter: function ReportAbuse::save");
     if (empty($this->parent_type)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Parent type is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'parent type is Empty.');
     }
     if (empty($this->parent_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Parent id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Parent id is missing.');
     }
     if (empty($this->body)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: body of Report abuse is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Body of Report can\'t be empty.');
     }
     if (empty($this->reporter_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Reporter id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Log into People Aggregator before sending report');
     }
     if (!User::user_exist((int) $this->reporter_id)) {
         Logger::log(" Throwing exception USER_NOT_FOUND | Message: User does not exist", LOGGER_ERROR);
         throw new PAException(USER_NOT_FOUND, 'User does not exist.');
     }
     if (!$this->is_valid_type($this->parent_type)) {
         Logger::log(" Throwing exception INVALID_ARGUMENTS | Message: Not a valid parent type", LOGGER_ERROR);
         throw new PAException(INVALID_ARGUMENTS, 'parent type is invalid');
     }
     $sql = "INSERT INTO {report_abuse}\n      (parent_type, parent_id, reporter_id, body, created)\n      VALUES (?, ?, ?, ?, ?)";
     $this->created = time();
     $data = array($this->parent_type, $this->parent_id, $this->reporter_id, $this->body, $this->created);
     Dal::query($sql, $data);
     $this->report_id = Dal::insert_id();
     Logger::log("Exit: function ReportAbuse::save");
     return $this->report_id;
 }
 public function save()
 {
     Logger::log("Enter: function ActivityType::save()");
     if (empty($this->title) || empty($this->points) || empty($this->type)) {
         Logger::log("Throwing exception in ActivityType::save(). Required parameter missing.", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, "Required parameter missing");
     }
     $sql = "INSERT INTO {activity_types} (id, title, description, type, points) " . "VALUES ('" . $this->id . "', '" . $this->title . "', '" . $this->description . "', '" . $this->type . "', " . $this->points . ") " . "ON DUPLICATE KEY UPDATE title = '" . $this->title . "', description = '" . $this->description . "', type = '" . $this->type . "', points = " . $this->points;
     $res = Dal::query($sql);
     $this->id = Dal::insert_id();
     Logger::log("Exit: function ActivityType::save()");
 }
 /**
  * This function saves an entry in footer_links table
  * input type: Values are set for object eg links = new FooterLink; $links->caption= 'sys';
  * return type: id
  */
 public function save()
 {
     Logger::log("Enter: function FooterLink::save()");
     if (!empty($this->id)) {
         $sql = "UPDATE {footer_links} SET caption = ?, url = ?, is_active = ?, extra = ? WHERE id = " . $this->id;
     } else {
         $sql = "INSERT INTO {footer_links} (caption, url, is_active, extra) VALUES \n        (?, ?, ?, ?) ";
     }
     $data = array($this->caption, $this->url, $this->is_active, $this->extra);
     $res = Dal::query($sql, $data);
     $id = Dal::insert_id();
     Logger::log("Enter: function FooterLink::save");
     return $id;
 }
Exemple #4
0
 /**
  * Purpose: this function creates a new role
  * @param class variables that must be set prior to calling this function
  * Class variables are set by method set_vars();
  * @return id of the role created
  */
 public function create()
 {
     Logger::log("Enter: function Roles::create");
     $this->created = $this->changed = time();
     if (empty($this->name)) {
         throw new PAException(REQUIRED_PARAMETERS_MISSING, "Please specify Role name,it can not be left blank.");
     }
     if (empty($this->description)) {
         throw new PAException(REQUIRED_PARAMETERS_MISSING, "Please specify Role description ,it can not be left blank.");
     }
     $res = Dal::query("INSERT INTO {admin_roles} (name, description, created, changed) VALUES (?, ?, ?, ?)", array($this->name, $this->description, $this->created, $this->changed));
     $this->id = Dal::insert_id();
     Logger::log("Exit: function Roles::create");
     return $this->id;
 }
 public function save()
 {
     if ($this->badge_id) {
         Dal::query("UPDATE {blog_badges} SET badge_config=? WHERE user_id=? AND badge_id=?", array(serialize($this->config), $this->user_id, $this->badge_id));
     } else {
         if (!$this->user_id) {
             throw new PAException(OPERATION_NOT_PERMITTED, "New widget requires user_id to save");
         }
         if (!$this->badge_tag) {
             throw new PAException(OPERATION_NOT_PERMITTED, "New widget requires badge_tag to save");
         }
         if (!$this->title) {
             $this->title = $this->badge_tag;
         }
         Dal::query("INSERT INTO {blog_badges} SET user_id=?, badge_tag=?, title=?, badge_config=?", array($this->user_id, $this->badge_tag, $this->title, serialize($this->config)));
         $this->badge_id = Dal::insert_id();
     }
 }
 public function __construct($host, $noisy = FALSE)
 {
     if (!trim($host)) {
         throw new PAException(BAD_PARAMETER, "Invalid host");
     }
     $dom = Dal::query_one_assoc("SELECT * FROM spam_domains WHERE domain=?", array($host));
     if ($dom) {
         // exists
         foreach ($dom as $k => $v) {
             $this->{$k} = $v;
         }
     } else {
         // need to create it
         $this->domain = $host;
         $this->count = $this->blacklisted = $this->whitelisted = 0;
         if ($noisy) {
             echo "Querying blacklists for {$host}:";
         }
         foreach (array("multi.uribl.com", "multi.surbl.org") as $bl) {
             if ($noisy) {
                 echo " {$bl}";
             }
             if (gethostbyname("{$host}.{$bl}") != "{$host}.{$bl}") {
                 $this->blacklisted = DOMAIN_BLACKLISTED_AUTOMATICALLY;
                 if ($noisy) {
                     echo " BLACKLISTED!";
                 }
                 break;
             }
         }
         if ($noisy) {
             echo "\n";
         }
         Dal::query("INSERT INTO spam_domains SET domain=?, blacklisted=?", array($this->domain, $this->blacklisted));
         $this->id = Dal::insert_id();
     }
 }
Exemple #7
0
 public static function link($file_id, $params)
 {
     //INNODB TODO: start transaction
     // Verify file
     list($incomplete, $link_count) = Dal::query_one("SELECT incomplete, link_count FROM files WHERE file_id=?", array($file_id));
     if ($incomplete) {
         throw new PAException(FILE_NOT_FOUND, "File {$file_id} was not completely saved; cannot create a link to it");
     }
     // Validate $params and build SQL to add link
     $role = $params['role'];
     if (empty($role)) {
         throw new PAException(BAD_PARAMETER, "Storage role must be provided to link()");
     }
     $sql = "INSERT INTO file_links SET file_id=?, role=?";
     $sqlargs = array($file_id, $role);
     $required_params = NULL;
     unset($params['role']);
     switch ($role) {
         case 'thumb':
             $required_params = array("file", "dim");
             break;
         case 'media':
             $required_params = array("network", "content");
             break;
         case 'avatar':
         case 'header':
             if (!empty($params['user'])) {
                 $required_params = array("user");
             } else {
                 if (!empty($params['group'])) {
                     $required_params = array("network", "group");
                 } else {
                     $required_params = array("network");
                 }
             }
             break;
         case 'ad':
             $required_params = array("network", "ad");
             break;
         case 'emblem':
             $required_params = array("network");
             break;
         default:
             throw new PAException(BAD_PARAMETER, "Invalid storage role '{$role}'");
     }
     // Map user param names to SQL column names
     $param_name_mapping = array("network" => "network_id", "user" => "user_id", "group" => "group_id", "ad" => "ad_id", "content" => "content_id", "file" => "parent_file_id", "dim" => "dim");
     // Process required params, removing them from $params as we go
     foreach ($required_params as $param_name) {
         if (empty($params[$param_name])) {
             throw new PAException(BAD_PARAMETER, "Required parameter '{$param_name}' (for role {$role}) not provided to link() for file {$file_id}");
         }
         $value = $params[$param_name];
         switch ($param_name) {
             case "network":
             case "user":
             case "group":
             case "ad":
             case "content":
                 if (!is_numeric($value)) {
                     throw new PAException(BAD_PARAMETER, "'{$param_name}' parameter must be numeric");
                 }
                 break;
             case "dim":
                 if (!preg_match("/^\\d+x\\d+\$/", $value)) {
                     throw new PAException(BAD_PARAMETER, "'dim' parameter must be of the format <width>x<height>");
                 }
                 break;
             case "file":
                 $parent_file_id = $value;
                 if ($parent_file_id == $file_id) {
                     throw new PAException(BAD_PARAMETER, "Cannot link a file in as a derivative of itself (file_id == parent_file_id == {$file_id})");
                 }
                 $parent_file = Dal::query_one("SELECT incomplete FROM files WHERE file_id=?", array($parent_file_id));
                 if (empty($parent_file)) {
                     throw new PAException(FILE_NOT_FOUND, "Parent of derivative file in link must exist (file {$file_id}, parent file {$parent_file_id})");
                 }
                 break;
         }
         $sql .= ", " . $param_name_mapping[$param_name] . "=?";
         $sqlargs[] = $params[$param_name];
         unset($params[$param_name]);
     }
     // If $params is not empty by now, we must have some extra params, that aren't allowed
     if (count($params) > 0) {
         throw new PAException(BAD_PARAMETER, "Invalid parameters (" . implode(", ", array_keys($params)) . ") provided to link() for role {$role}, file {$file_id}");
     }
     // Now store the link and increment the file link count
     Dal::query($sql, $sqlargs);
     $link_id = Dal::insert_id();
     Dal::query("UPDATE files SET last_linked=NOW(), link_count=link_count+1 WHERE file_id=?", array($file_id));
     //INNODB TODO: commit
     return $link_id;
 }
 /**
  * Saves network to databse.
  * used for creating and updating the network
  * @access public.
  * called after $this->set_params()
  */
 public function save()
 {
     global $error, $error_msg;
     $error = false;
     Logger::log("[ Enter: function Network::save]\n");
     //first check whether it is insert or update
     // global var $path_prefix has been removed - please, use PA::$path static variable
     if ($this->network_id) {
         $old_type = Network::find_network_type($this->network_id);
         //update
         $update_fields = array('name', 'tagline', 'category_id', 'description', 'extra', 'type', 'inner_logo_image');
         $sql = " UPDATE {networks} SET changed = ? ";
         $data_array = array(time());
         foreach ($update_fields as $field) {
             if (isset($this->{$field})) {
                 $sql .= " , {$field} = ? ";
                 array_push($data_array, $this->{$field});
             }
         }
         $sql .= " WHERE network_id = ? ";
         array_push($data_array, $this->network_id);
         $res = Dal::query($sql, $data_array);
         //fix for changing a network from private to public
         //the waiting_members must be changed to members
         $new_type = $this->type;
         if ($old_type == PRIVATE_NETWORK_TYPE && $new_type == REGULAR_NETWORK_TYPE) {
             Network::approve_all($this->network_id);
         }
     } else {
         //insert
         // here we have to do a lot of steps
         //first check if network already exists with same address
         if (Network::check_already($this->address)) {
             Logger::log("Thowing Exception NETWORK_ALREADY_EXISTS");
             throw new PAException(NETWORK_ALREADY_EXISTS, "Network with same address already exists");
         }
         // checks the permissions of directory network
         $network_folder = PA::$project_dir . "/networks";
         if (!is_writable($network_folder)) {
             Logger::log("Thowing Exception NETWORK_DIRECTORY_PERMISSION_ERROR");
             throw new PAException(NETWORK_DIRECTORY_PERMISSION_ERROR, "Network folder ({$network_folder}) is not writable. Please check the permissions");
         }
         //if we have come this far we can insert the network easily
         // TODO add acl permission check
         //insert into networks
         $this->created = time();
         $this->type = $this->type ? $this->type : REGULAR_NETWORK_TYPE;
         $res = Dal::query("INSERT INTO {networks} (name, address, tagline, type,category_id, description,is_active, created, changed, extra, member_count, owner_id, inner_logo_image) VALUES ( ?, ?, ?,?, ?, ?, ?, ?, ?, ?, 1, ?, ? )", array($this->name, $this->address, $this->tagline, $this->type, $this->category_id, $this->description, 1, $this->created, $this->changed, $this->extra, $this->user_id, $this->inner_logo_image));
         $this->network_id = Dal::insert_id();
         //insert into networks_users
         $user_created = Dal::query_first("SELECT created FROM users WHERE user_id=?", $this->user_id);
         $res = Dal::query("INSERT INTO {networks_users} (network_id, user_id, user_type, created) VALUES (?, ?, ?, ?)", array($this->network_id, $this->user_id, NETWORK_OWNER, $user_created));
         //Now we have inserted new network we need to create other directory and config files as well
         try {
             $this->do_network_setup();
         } catch (PAException $e) {
             $error = TRUE;
             $error_msg = "{$e->message}";
         }
         if ($error) {
             $this->do_rollback();
             throw new PAException(NETWORK_INTERNAL_ERROR, "Some internal error occured while setting up the network. Message: {$error_msg}");
         }
     }
     //.. insert
     Logger::log("[ Exit: function Network::save]\n");
     return $this->network_id;
 }
 function save()
 {
     $ct = Dal::query_first("SELECT COUNT(*) FROM {fans} WHERE is_active=1 AND user_id=? AND subject_type=? AND subject_id=?", array($this->user_id, $this->subject_type, $this->subject_id));
     $is_new = $ct ? 0 : 1;
     if ($is_new) {
         if (!isset($this->is_active)) {
             $this->is_active = 1;
         }
     }
     $sql = $is_new ? "INSERT INTO {fans} SET " : "UPDATE {fans} SET ";
     $args = array();
     $set_fragments = array();
     foreach (Fan::$columns as $col) {
         switch ($col) {
             case 'fan_id':
                 // never set
                 continue;
             case 'updated':
                 // always set automatically
                 $set_fragments[] = "{$col}=NOW()";
                 break;
             case 'created':
                 // set automatically if new, otherwise copy
                 if ($is_new) {
                     $set_fragments[] = "{$col}=NOW()";
                     break;
                 }
                 // else fallthrough
             // else fallthrough
             default:
                 $set_fragments[] = "{$col}=?";
                 $args[] = $this->{$col};
         }
     }
     $sql .= implode(", ", $set_fragments);
     if (!$is_new) {
         $sql .= " WHERE fan_id=?";
         $args[] = $this->fan_id;
     }
     Dal::query($sql, $args);
     if ($is_new) {
         $this->fan_id = Dal::insert_id();
     }
     /*
         // update denormalization
         Dal::query("UPDATE {items} SET fan_count=(
           SELECT COUNT(*) FROM {fans} WHERE is_active=1 AND subject_type=? AND subject_id=?)
           WHERE is_active=1 AND subject_type=? AND subject_id=?", array(
           $this->subject_type, $this->subject_id,
           $this->subject_type, $this->subject_id));
         Dal::query("UPDATE {users} SET fan_count=(
           SELECT COUNT(*) FROM {fans} WHERE is_active=1 AND user_id=?)
           WHERE is_active=1 AND user_id=?", array(
           $this->user_id, $this->user_id));
     */
     return $this->fan_id;
 }
Exemple #10
0
 /**
  * Load the updated_tags_id by inserting the given tags to database
  * If the tag is already present in database then it will retrieve that value
  * Else this function will enter the tag into the database and then retrieve the value of tag_id and tag_name.
  *
  * @param array tags contain the tags whose tag_id needs to be returned
  *
  * @return array
  */
 static function load_tag_ids($tags)
 {
     Logger::log("Enter: function Tag::load_tag_ids");
     $updated_tags_id = array();
     $num = count($tags);
     for ($i = 0; $i <= $num - 1; $i++) {
         $sql = 'SELECT tag_id FROM {tags} WHERE tag_name= ?';
         $data = array($tags[$i]);
         $res = Dal::query($sql, $data);
         if ($res->numRows() > 0) {
             $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
             $updated_tags_id[$i] = $row->tag_id;
         } else {
             $sql = 'INSERT into {tags} (tag_name) values (?)';
             $data = array(strtolower($tags[$i]));
             Dal::query($sql, $data);
             //find last insert id
             $updated_tags_id[$i] = Dal::insert_id();
         }
     }
     Logger::log("Exit: function Tag::load_tag_ids");
     return $updated_tags_id;
 }
 /**
  * This function saves an entry for advertisements table
  * input type: Values are set for object eg advertisement = new Advertisement; $advertisement->title= 'sys';
  * return type: ad_id
  */
 public function save()
 {
     Logger::log("Enter: function Advertisement::save()");
     if (empty($this->title)) {
         Logger::log("Exit: function Advertisement::save(). Title of the ad found blank.");
         throw new CNException(BAD_PARAMETER, __('Ad Title can not have empty.'));
     }
     if (empty($this->page_id)) {
         Logger::log("Exit: function Advertisement::save(). Page not specified.");
         throw new CNException(BAD_PARAMETER, __('Ad Target page is not specified.'));
     }
     $data = array($this->user_id, $this->ad_image, $this->url, $this->ad_script, $this->title, $this->description, $this->page_id, $this->orientation, $this->created, $this->changed, $this->is_active);
     if (!empty($this->ad_id)) {
         $sql = "UPDATE {advertisements} SET user_id = ?, ad_image = ?, url = ?, ad_script = ?, title = ?, description = ?, page_id = ?, orientation = ?, created = ?, changed = ?, is_active = ? WHERE ad_id = ?";
         array_push($data, $this->ad_id);
     } else {
         $sql = "INSERT INTO {advertisements} (user_id, ad_image, url, ad_script, title, description, page_id, orientation, created, changed, is_active, type, group_id) VALUES\n        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
         array_push($data, $this->type);
         array_push($data, @$this->group_id);
     }
     $res = Dal::query($sql, $data);
     $ad_id = Dal::insert_id();
     Logger::log("Enter: function Advertisement::save");
     return $ad_id;
 }
 /**
  * Insert a new Record - dynamic method: insert_UserPopularity()
  *
  *
  * Generated with the DalClassGenerator created by: 
  * Zoran Hron <*****@*****.**> 
  *
  * @param popularity
  * @param time
  * @result id
  **/
 public function insert_UserPopularity($popularity, $time)
 {
     // items to be inserted in the database
     $params = array(null, $popularity, $time);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { user_popularity } ( user_id, popularity, time ) VALUES ( ?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
Exemple #13
0
 /**
  * Save the persona data to the database.
  *
  * When creating a new persona, set all the attributes for the persona 
  * (except persona_id) and call save. Save will set the persona_id for 
  * the persona.
  *
  */
 public function save()
 {
     Logger::log("Enter: function Persona::save");
     // If we have decoded the JSON coniguration string into the structured
     // configuration data, it will be non-null, so encode it back as a JSON
     // string into configuration, to save it.
     if ($this->configuration_data != null) {
         $this->encode_configuration();
     }
     try {
         if (!$this->user_id || !$this->persona_service_id) {
             Logger::log("Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Required parameters missing", LOGGER_ERROR);
             throw new PAException(REQUIRED_PARAMETERS_MISSING, "Required parameters missing");
         }
         if ($this->is_new) {
             $this->is_new = false;
             $sql = 'INSERT INTO {personas} (user_id, persona_service_id, sequence, name, configuration) values (?, ?, ?, ?, ?)';
             $data = array($this->user_id, $this->persona_service_id, $this->sequence, $this->name, $this->configuration);
             Dal::query($sql, $data);
             $this->persona_id = Dal::insert_id();
         } else {
             $sql = 'UPDATE {personas} SET user_id = ?, persona_service_id = ?, sequence = ?, name = ?, configuration = ? WHERE persona_id = ?';
             $data = array($this->user_id, $this->persona_service_id, $this->sequence, $this->name, $this->configuration, $this->persona_id);
             Dal::query($sql, $data);
         }
         // All done - commit to database.
         Dal::commit();
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: function Persona::save");
 }
 /**
  * saves category data 
  * @access public
  * if category_id is set it updates else inserts
  * return null
  */
 public function save()
 {
     Logger::log("Enter: function Category::save");
     //check for required parameters
     if (!$this->name) {
         Logger::log("Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Required parameters missing", LOGGER_ERROR);
         throw new CNException(REQUIRED_PARAMETERS_MISSING, "Required parameters missing");
     }
     // ..eof check
     if ($this->category_id) {
         //update
         // TODO to move category's position
         $this->changed = time();
         $sql = "UPDATE {categories} SET name = ?, description = ?, type = ?, changed = ? WHERE category_id = ? AND is_active = 1";
         $data = array($this->name, $this->description, $this->type, $this->changed, $this->category_id);
         $res = Dal::query($sql, $data);
     } else {
         //insert
         $position = Category::get_position($this->parent_id);
         $this->created = time();
         $this->changed = $this->created;
         $sql = 'INSERT into {categories} ( name, description, type, is_active, created, changed ) values ( ?, ?, ?, ?, ?, ? )';
         $data = array($this->name, $this->description, $this->type, ACTIVE, $this->created, $this->changed);
         $res = Dal::query($sql, $data);
         $insert_id = Dal::insert_id();
         $position .= $insert_id . ">";
         $sql = " UPDATE {categories} SET position = ? WHERE category_id = ? ";
         $data = array($position, $insert_id);
         $res = Dal::query($sql, $data);
     }
     //..eof insert else
     Logger::log("Exit: function Category::save");
     return;
 }
 /**
  * Insert a new Record - dynamic method: insert_PaForumPost()
  *
  *
  * Generated with the DalClassGenerator created by: 
  * Zoran Hron <*****@*****.**> 
  *
  * @param title
  * @param content
  * @param user_id
  * @param parent_id
  * @param thread_id
  * @param is_active
  * @param created_at
  * @param updated_at
  * @param modified_by
  * @result id
  **/
 public function insert_PaForumPost($title, $content, $user_id, $parent_id, $thread_id, $is_active, $created_at, $updated_at, $modified_by)
 {
     // items to be inserted in the database
     $params = array(null, $title, $content, $user_id, $parent_id, $thread_id, $is_active, $created_at, $updated_at, $modified_by);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { pa_forum_post } ( id, title, content, user_id, parent_id, thread_id, is_active, created_at, updated_at, modified_by ) VALUES ( ?,?,?,?,?,?,?,?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
 public function save()
 {
     Logger::log("Enter: Event::save");
     // check for complete info
     if (empty($this->event_title)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: event_title is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Please supply an Event Title.');
     }
     $this->title = $this->event_title;
     if (empty($this->start_time)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: start_time is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Please specify the Start Time.');
     }
     if (empty($this->end_time)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: end_time is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Please specify the End Time.');
     }
     // serialize event_data for storage
     $event_data = "";
     if (!empty($this->event_data)) {
         $event_data = serialize($this->event_data);
     }
     // make end_time sane (can only be same or after start_time)
     if (strtotime($this->end_time) <= strtotime($this->start_time)) {
         $this->end_time = $this->start_time;
     }
     $this->author_id = $this->user_id;
     $this->body = $this->event_data['description'];
     // are we creating a new one?
     if (!$this->event_id) {
         /*
         if (empty($this->content_id)) {
             Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: content_id is empty", LOGGER_ERROR);
             throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Content id is missing.');
         }
         */
         // do we have a real User set as owner?
         if (!User::user_exist((int) $this->user_id)) {
             Logger::log(" Throwing exception USER_NOT_FOUND | Message: User does not exist", LOGGER_ERROR);
             throw new PAException(USER_NOT_FOUND, 'User does not exist.');
         }
         // save a Content
         parent::save();
         $sql = "INSERT INTO events \n      (content_id, user_id, event_title, start_time, end_time, event_data) \n      VALUES (?, ?, ?, ?, ?, ?)";
         $data = array($this->content_id, $this->user_id, $this->event_title, $this->start_time, $this->end_time, $event_data);
     } else {
         // save as Content
         parent::save();
         $sql = "UPDATE {events} SET " . "event_title = ?, start_time = ?, end_time = ?, event_data = ? " . "WHERE event_id = ?";
         $data = array($this->event_title, $this->start_time, $this->end_time, $event_data, $this->event_id);
     }
     // write to DB
     try {
         Dal::query($sql, $data);
         if (!$this->event_id) {
             // newly created
             $this->event_id = Dal::insert_id();
         } else {
             // update any existing EventAssociations
             EventAssociation::update_assocs_for_event($this);
         }
         // Finally - commit our changes to the DB
         Dal::commit();
     } catch (PAException $e) {
         // roll back database operations and re-throw the exception
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: Event::save");
 }
 /**
  * This function saves an entry for advertisements table
  * input type: Values are set for object eg advertisement = new Advertisement; $advertisement->title= 'sys';
  * return type: ad_id
  */
 public function save()
 {
     Logger::log("Enter: function Advertisement::save()");
     if (!empty($this->ad_id)) {
         $sql = "UPDATE {advertisements} SET user_id = ?, ad_image = ?, url = ?, ad_script = ?, title = ?, description = ?, page_id = ?, orientation = ?, created = ?, changed = ?, is_active = ? WHERE ad_id = " . $this->ad_id;
     } else {
         $sql = "INSERT INTO {advertisements} (user_id, ad_image, url, ad_script, title, description, page_id, orientation, created, changed, is_active) VALUES \n        (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
     }
     $data = array($this->user_id, $this->ad_image, $this->url, $this->ad_script, $this->title, $this->description, $this->page_id, $this->orientation, $this->created, $this->changed, $this->is_active);
     $res = Dal::query($sql, $data);
     $ad_id = Dal::insert_id();
     Logger::log("Enter: function Advertisement::save");
     return $ad_id;
 }
 /**
  * Saves thread if category_id is set
  * Saves reply if parent_message_id is set
  * Makes association of category-thread / message-reply
  * @access public
  * @param set_category_id(category_id),set_parent_message_id(parent_message_id) 
  */
 function save($uid = NULL, $is_insert = 1)
 {
     Logger::log("Enter: function MessageBoard::save");
     // validate $this->user_id
     if ($this->user_id < 1 && $this->user_id !== NULL) {
         throw new PAException(INVALID_ID, "MessageBoard::user_id variable must be either NULL or a valid user ID when posting.");
     }
     //exception if anything go wrong
     // anonymous user cant start a new thread
     if ($is_insert == 1) {
         if ($this->parent_type != PARENT_TYPE_MESSAGE) {
             if (!$this->user_id || $this->user_id == '-1') {
                 Logger::log(" Throwing exception USER_NOT_LOGGED_IN | Message: {$res->getMessage}()", LOGGER_ERROR);
                 throw new PAException(USER_NOT_LOGGED_IN, "Anonymous User cant start a thread");
             }
         } else {
             // anonymous user can reply only if allowed
             $check = MessageBoard::check_annonymous_allowed($this->parent_id);
             if (!$check && !$uid) {
                 Logger::log(" Throwing exception USER_NOT_LOGGED_IN | Message: {$res->getMessage}()", LOGGER_ERROR);
                 throw new PAException(USER_NOT_LOGGED_IN, "Anonymous user cant post a comment");
             }
         }
         //exception if anything go wrong EOF
         $this->created = time();
         $this->changed = $this->created;
         if ($this->user_id == '') {
             $this->user_id = ANONYMOUS_USER_ID;
         }
         $sql = " INSERT into {boardmessages} ( title, body, created, changed, user_id, allow_anonymous, user_name, email, homepage, parent_id, parent_type) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
         $data = array($this->title, $this->body, $this->created, $this->changed, $this->user_id, $this->allow_anonymous, $this->user_name, $this->email, $this->homepage, $this->parent_id, $this->parent_type);
         Dal::query($sql, $data);
         $insert_id = Dal::insert_id();
     } else {
         $this->changed = time();
         $sql = " UPDATE {boardmessages} set title =? , body =? ,changed=? , allow_anonymous = ? WHERE  boardmessage_id=?";
         $data = array($this->title, $this->body, $this->changed, $this->allow_anonymous, $this->boardmessage_id);
         Dal::query($sql, $data);
         $insert_id = $this->boardmessage_id;
     }
     return $insert_id;
     Logger::log("Exit: function MessageBoard::save");
 }
 function save()
 {
     $is_new = empty($this->review_id);
     if ($is_new) {
         if (!isset($this->is_active)) {
             $this->is_active = 1;
         }
     }
     $sql = $is_new ? "INSERT INTO {reviews} SET " : "UPDATE {reviews} SET ";
     $args = array();
     $set_fragments = array();
     foreach (Review::$columns as $col) {
         switch ($col) {
             case 'review_id':
                 // never set
                 continue;
             case 'updated':
                 // always set automatically
                 $set_fragments[] = "{$col}=NOW()";
                 break;
             case 'created':
                 // set automatically if new, otherwise copy
                 if ($is_new) {
                     $set_fragments[] = "{$col}=NOW()";
                     break;
                 }
                 // else fallthrough
             // else fallthrough
             default:
                 $set_fragments[] = "{$col}=?";
                 $args[] = $this->{$col};
         }
     }
     $sql .= implode(", ", $set_fragments);
     if (!$is_new) {
         $sql .= " WHERE review_id=?";
         $args[] = $this->review_id;
     }
     Dal::query($sql, $args);
     if ($is_new) {
         $this->review_id = Dal::insert_id();
     }
 }
 public static function get_or_make_static($path, $mime_type = "application/octet-stream")
 {
     if (!$path) {
         throw new CNException(INVALID_ID, "Storage::get_or_make_static() requires a filename");
     }
     if (!file_exists(PA::$project_dir . "/web/{$path}")) {
         throw new CNException(FILE_NOT_FOUND, "File {$path} does not exist");
     }
     // Call this for files distributed with PA that need to be in
     // Storage (FixedStorage backend) so they can be resized.
     $r = Dal::query_one_assoc("SELECT file_id FROM files WHERE storage_backend='fixed' AND local_id=?", array($path));
     if (!empty($r)) {
         return new StoredFile($r);
     }
     // Not in storage -- add it
     if (strlen($path) > 255) {
         throw new CNException(INVALID_ID, "Path of file to store in fixed storage is too long - max 255 chars ({$path})");
     }
     $path_bits = explode("/", $path);
     $leaf = $path_bits[count($path_bits) - 1];
     Dal::query("INSERT INTO files SET filename=?, file_class='fixed', mime_type=?, created=NOW(), incomplete=0, storage_backend='fixed', local_id=?", array($leaf, $mime_type, $path));
     return new StoredFile(Dal::insert_id());
 }
 /**
  * Insert a new Record - dynamic method: insert_PaForumsUsers()
  *
  *
  * Generated with the DalClassGenerator created by: 
  * Zoran Hron <*****@*****.**> 
  *
  * @param board_id
  * @param user_status
  * @param is_active
  * @param date_join
  * @result id
  **/
 public function insert_PaForumsUsers($user_id = null, $board_id, $user_status, $is_active, $date_join)
 {
     // items to be inserted in the database
     $params = array($user_id, $board_id, $user_status, $is_active, $date_join);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { pa_forums_users } ( user_id, board_id, user_status, is_active, date_join ) VALUES ( ?,?,?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
 /**
  * Insert a new Record - dynamic method: insert_UserContact()
  *
  *
  * Generated with the DalClassGenerator created by:
  * Zoran Hron <*****@*****.**>
  *
  * @param user_id
  * @param contact_name
  * @param contact_email
  * @param contact_extra
  * @param contact_type
  * @result id
  **/
 public function insert_UserContact($user_id, $contact_name, $contact_email, $contact_extra, $contact_type)
 {
     // items to be inserted in the database
     $params = array(null, $user_id, $contact_name, $contact_email, $contact_extra, $contact_type);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { user_contact } ( id, user_id, contact_name, contact_email, contact_extra, contact_type ) VALUES ( ?,?,?,?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
 /**
  *   Method to save a category. Parameters for the function are class variables which are *   set by a setter function. 
  *   @param no parameters
  *   @access public
  */
 public function save_category()
 {
     Logger::log("Enter: function Links::save_category");
     /*  Check for category with existing name */
     $condition = array('category_name' => $this->category_name, 'user_id' => $this->user_id, 'is_active' => $this->is_active);
     $data_array = $this->load_category($condition);
     if (count($data_array) == 0) {
         $sql = "INSERT INTO {linkcategories} (category_name, user_id, created, changed, is_active) values (?, ?, ?, ?, ?)";
         $data = array($this->category_name, $this->user_id, $this->created, $this->changed, $this->is_active);
         $res = Dal::query($sql, $data);
     } else {
         /*  User has already created a category with the given name */
         Logger::log("Throwing exception LINK_CATEGORY_EXISTS | Link category already exists", LOGGER_ERROR);
         throw new CNException(LINK_CATEGORY_EXISTS, "Link category already exists.");
     }
     $this->category_id = Dal::insert_id();
     Logger::log("Exit: function Links::save_category");
     return $this->category_id;
 }
Exemple #24
0
 /**
   this function required parent type and parent id for submit any comment 
 */
 public function save_comment()
 {
     Logger::log("Enter: function Comment::save_comment");
     // setting the variable for the spam
     $is_new_comment = !$this->comment_id;
     if ($is_new_comment) {
         if (!isset($this->ip_addr)) {
             $this->populate_server_vars();
         }
         $this->created = $this->changed = time();
     }
     // inserting the data into database
     $sql = "INSERT INTO {comments} ( content_id, subject, comment, created, changed, is_active, user_id, name, email, homepage, ip_addr, referrer, user_agent, parent_type, parent_id) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
     $data = array($this->content_id, $this->subject, $this->comment, $this->created, $this->changed, $this->is_active, $this->user_id, $this->name, $this->email, $this->homepage, $this->ip_addr, $this->referrer, $this->user_agent, $this->parent_type, $this->parent_id);
     $res = Dal::query($sql, $data);
     $this->comment_id = Dal::insert_id();
     Logger::log("Saved comment {$this->comment_id} by user {$this->user_id} on content ID {$this->content_id}", LOGGER_ACTION);
     $this->spam_analyze();
     Logger::log("Exit: function Comment::save_comment \n", LOGGER_INFO);
 }
 /**
  * Insert a new Record - dynamic method: insert_PaForum()
  *
  *
  * Generated with the DalClassGenerator created by:
  * Zoran Hron <*****@*****.**>
  *
  * @param title
  * @param description
  * @param is_active
  * @param category_id
  * @param sort_order
  * @param icon
  * @param created_at
  * @param updated_at
  * @result id
  **/
 public function insert_PaForum($title, $description, $is_active, $category_id, $sort_order, $icon, $created_at, $updated_at)
 {
     // items to be inserted in the database
     $params = array(null, $title, $description, $is_active, $category_id, $sort_order, $icon, $created_at, $updated_at);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { pa_forum } ( id, title, description, is_active, category_id, sort_order, icon, created_at, updated_at ) VALUES ( ?,?,?,?,?,?,?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
 /**
  * Insert a new Record - dynamic method: insert_PaForumBoard()
  *
  *
  * Generated with the DalClassGenerator created by: 
  * Zoran Hron <*****@*****.**> 
  *
  * @param owner_id
  * @param title
  * @param description
  * @param type
  * @param theme
  * @param settings
  * @param is_active
  * @param created_at
  * @result id
  **/
 public function insert_PaForumBoard($owner_id, $network_id, $title, $description, $type, $theme, $settings, $is_active, $created_at)
 {
     // items to be inserted in the database
     $params = array(null, $owner_id, $network_id, $title, $description, $type, $theme, $settings, $is_active, $created_at);
     $__id = null;
     // insert query
     $sql = "INSERT INTO { pa_forum_board } ( id, owner_id, network_id, title, description, type, theme, settings, is_active, created_at ) VALUES ( ?,?,?,?,?,?,?,?,?,? );";
     // perform insert in the database
     $res = Dal::query($sql, $params);
     if ($res) {
         $__id = Dal::insert_id();
     }
     return $__id;
 }
 public function save()
 {
     Logger::log("Enter: EventAssociation::save");
     // check for complete info
     if (empty($this->event_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: event_id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'event_id is missing.');
     }
     if (empty($this->assoc_target_type)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: assoc_target_type is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'assoc_target_type is missing.');
     }
     if (empty($this->assoc_target_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: assoc_target_id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'assoc_target_id is missing.');
     }
     if (empty($this->assoc_target_name)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: assoc_target_name is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'assoc_target_name is missing.');
     }
     // depending on assoc_target_type check if network|group|user exists
     switch ($this->assoc_target_type) {
         case "network":
             // network of assoc_target_id exists?
             // this check should maybe be part of the Network class?
             $res = Dal::query("SELECT COUNT(*) FROM {networks} \n          WHERE network_id=? AND is_active=1", array($this->assoc_target_id));
             if (!$res->numRows()) {
                 Logger::log(" Throwing exception NETWORK_NOT_FOUND | Message: Network does not exist", LOGGER_ERROR);
                 throw new PAException(NETWORK_NOT_FOUND, 'Network does not exist.');
             }
             break;
         case "group":
             // group of assoc_target_id exists?
             $res = Dal::query("SELECT COUNT(*) FROM {groups} \n          WHERE group_id=?", array($this->assoc_target_id));
             if (!$res->numRows()) {
                 Logger::log(" Throwing exception GROUP_NAME_NOT_EXIST | Message: Group does not exist", LOGGER_ERROR);
                 throw new PAException(GROUP_NAME_NOT_EXIST, 'Group does not exist.');
             }
             break;
         case "user":
             // user of assoc_target_id exists?
             if (!User::user_exist($this->assoc_target_id)) {
                 Logger::log(" Throwing exception USER_NOT_FOUND | Message: User does not exist", LOGGER_ERROR);
                 throw new PAException(USER_NOT_FOUND, 'User does not exist.');
             }
             break;
         default:
             // oh-oh, not a valid assoc_target_type!!
             Logger::log(" Throwing exception BAD_PARAMETER | Message: " . $this->assoc_target_type . " is not a valid assoc_target_type", LOGGER_ERROR);
             throw new PAException(BAD_PARAMETER, $this->assoc_target_type . " is not a valid assoc_target_type");
             break;
     }
     // check to prevent duplicate associations
     if (EventAssociation::assoc_exists($this->assoc_target_type, $this->assoc_target_id, $this->event_id)) {
         Logger::log(" Throwing exception BAD_PARAMETER | Message: " . "There already is an EventAsssociation for this network, group or user.", LOGGER_ERROR);
         throw new PAException(BAD_PARAMETER, "The Event is already associated to this " . $this->assoc_target_type . ".");
     }
     if (!Event::exists($this->event_id)) {
         Logger::log(" Throwing exception EVENT_NOT_EXIST | Message: Event does not exist", LOGGER_ERROR);
         throw new PAException(EVENT_NOT_EXIST, 'Event does not exist.');
     }
     // load the Event if not already loaded
     if (!$this->event) {
         $this->load_event($this->event_id);
     }
     // serialize assoc_data for storage
     $assoc_data = "";
     if (!empty($this->assoc_data)) {
         $assoc_data = serialize($this->assoc_data);
     }
     // are we creating a new one?
     if (!$this->assoc_id) {
         // do we have a real User set as owner?
         if (!User::user_exist($this->user_id)) {
             Logger::log(" Throwing exception USER_NOT_FOUND | Message: User does not exist", LOGGER_ERROR);
             throw new PAException(USER_NOT_FOUND, 'User does not exist.');
         }
         // do we have an Event?
         if (!Event::exists($this->event->event_id)) {
             Logger::log(" Throwing exception EVENT_NOT_EXIST | Message: Event does not exist", LOGGER_ERROR);
             throw new PAException(EVENT_NOT_EXIST, 'Event does not exist.');
         }
         $sql = "INSERT INTO events_associations \n      (event_id, user_id, assoc_target_type, assoc_target_id, assoc_target_name, event_title, start_time, end_time, assoc_data) \n      VALUES (?,?,?,?,?,?,?,?,?)";
         $data = array($this->event->event_id, $this->user_id, $this->assoc_target_type, $this->assoc_target_id, $this->assoc_target_name, $this->event->event_title, $this->event->start_time, $this->event->end_time, $assoc_data);
     } else {
         $sql = "UPDATE {events_associations} SET " . "event_id = ?, user_id = ?, assoc_target_type = ?, assoc_target_id = ?,\n           assoc_target_name = ?, event_title = ?, start_time = ?, end_time = ?,\n           assoc_data = ?" . "WHERE assoc_id = ?";
         $data = array($this->event->event_id, $this->user_id, $this->assoc_target_type, $this->assoc_target_id, $this->assoc_target_name, $this->event->event_title, $this->event->start_time, $this->event->end_time, $assoc_data, $this->assoc_id);
     }
     // write to DB
     try {
         Dal::query($sql, $data);
         if (!$this->assoc_id) {
             $this->assoc_id = Dal::insert_id();
         }
         // Finally - commit our changes to the DB
         Dal::commit();
     } catch (PAException $e) {
         // roll back database operations and re-throw the exception
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: EventAssociation::save");
 }
 /**
  function Save()
  Required parameters :- Sender id, recipient id and body 
  @return testimonial id if data is successfully saved.
 */
 public function save()
 {
     Logger::log("Enter: function Testimonials::save");
     if (empty($this->sender_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: sender id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'sender id is missing.');
     }
     if (empty($this->recipient_id)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: recipient id is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'recipient id is missing.');
     }
     if (empty($this->body)) {
         Logger::log(" Throwing exception REQUIRED_PARAMETERS_MISSING | Message: body of testimonial is empty", LOGGER_ERROR);
         throw new PAException(REQUIRED_PARAMETERS_MISSING, 'Body of testimonial can\'t be empty.');
     }
     if ($this->sender_id == $this->recipient_id) {
         Logger::log(" Throwing exception INVALID_TESTIMONIAL | Message: sender id and recipient id is same", LOGGER_ERROR);
         throw new PAException(INVALID_ARGUMENTS, 'you can\'t write testimonial for your self');
     }
     if (!User::user_exist((int) $this->recipient_id)) {
         Logger::log(" Throwing exception USER_NOT_FOUND | Message: User does not exist", LOGGER_ERROR);
         throw new PAException(USER_NOT_FOUND, 'User does not exist.');
     }
     $this->status = PENDING;
     $this->is_active = ACTIVE;
     $this->created = time();
     $this->changed = time();
     $sql = "INSERT INTO testimonials \n      (sender_id, recipient_id, body, status, is_active, created, changed) \n      VALUES (?, ?, ?, ?, ?, ?, ?)";
     $data = array($this->sender_id, $this->recipient_id, $this->body, $this->status, $this->is_active, $this->created, $this->changed);
     Dal::query($sql, $data);
     $this->testimonial_id = Dal::insert_id();
     Logger::log("Exit: function Testimonials::save");
     return $this->testimonial_id;
 }