/**
  * This function saves an entry in static_pages table
  * input type: Values are set for object eg links = new StaticPage; $links->caption= 'sys';
  * return type: id
  */
 public function save()
 {
     Logger::log("Enter: function StaticPage::save()");
     if (!empty($this->id)) {
         $sql = "UPDATE {static_pages} SET caption = ?, page_text = ? WHERE id = " . $this->id;
         $data = array($this->caption, $this->page_text);
     } else {
         $page_id = Dal::next_id('static_pages');
         $sql = "INSERT INTO {static_pages} (caption, url, page_text) VALUES(?, ?, ?)";
         $data = array($this->caption, $this->url, $this->page_text);
     }
     $res = Dal::query($sql, $data);
     return $this->url;
 }
 /**
  * Public function to create a new feed for a user.
  * @param import_url, user_id
  * @return true on success, on failure will throw an exception
  */
 public function save()
 {
     Logger::log("Enter: ExternalFeed::save");
     //check for feed, whether it exists in the system or not
     $sql = 'SELECT feed_id FROM {external_feed} WHERE import_url = ?';
     $res = Dal::query($sql, array($this->import_url));
     if ($res->numRows()) {
         //feed url already exists in the system
         $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
         $this->feed_id = $row->feed_id;
         $sql = 'SELECT * FROM {user_feed} WHERE user_id = ? AND feed_id = ?';
         $res = Dal::query($sql, array($this->user_id, $this->feed_id));
         if ($res->numRows()) {
             // Import url already exists for given user.
             Logger::log("Feed url = {$this->import_url} already exists for user_id = {$this->user_id}");
             throw new CNException(IMPORT_URL_ALREADY_EXISTS, 'Import URL exists already for user.');
         } else {
             //saving feed for the user
             $this->save_user_feed();
             //refreshing the data for the feed
             $this->do_refresh = true;
             $this->refresh_feed_data();
         }
     } else {
         //This is a new feed and will be added to the existing feeds in the system
         $this->feed_id = Dal::next_id('ExternalFeed');
         $sql = 'INSERT INTO {external_feed} ( feed_id, import_url, max_posts, is_active, feed_type, last_build_date ) VALUES ( ?, ?, ?, ?, ?, ? )';
         $data = array($this->feed_id, $this->import_url, $this->max_posts, $this->is_active, $this->feed_type, time());
         try {
             //Inserting the feed to external_feed table
             $res = Dal::query($sql, $data);
         } catch (CNException $e) {
             Logger::log("ExternalFeed::save failed for user_id = {$this->user_id}. Associated sql = {$sql}");
             throw $e;
         }
         //saving feed for the user
         $this->save_user_feed();
         try {
             $this->import_posts();
             //importing the posts for given feed
         } catch (CNException $e) {
             Logger::log("{$e->message}");
             ExternalFeed::delete_user_feed($this->feed_id, $this->user_id);
             // deleting the inserted feed if import_posts fails.
             throw $e;
         }
     }
     Logger::log("Exit: ExternalFeed::save");
     return true;
 }
 /**
  * Save the persona service path 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 PersonaServicePath::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->persona_service_id || !$this->name) {
             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;
             $this->persona_service_path_id = Dal::next_id("persona_service_path");
             $sql = 'INSERT INTO {persona_service_paths} (persona_service_id, name, title, category, configuration, sequence, enabled) values (?, ?, ?, ?, ?, ?, ?)';
             $data = array($this->persona_service_id, $this->name, $this->title, $this->category, $this->configuration, $this->sequence, $this->enabled);
             Dal::query($sql, $data);
         } else {
             $sql = 'UPDATE {persona_service_paths} SET persona_service_id = ?, name = ?, title = ?, category = ?, configuration = ?, sequence = ?, enabled = ? WHERE persona_service_path_id = ?';
             $data = array($this->persona_service_id, $this->name, $this->title, $this->category, $this->configuration, $this->sequence, $this->enabled, $this->persona_service_path_id);
             Dal::query($sql, $data);
         }
         // All done - commit to database.
         Dal::commit();
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: function PersonaServicePath::save");
 }
Exemple #4
0
 /**
  * Saves object to databse.
  * @access protected.
  */
 protected function save()
 {
     if ($this->is_active == 0) {
         Logger::log(CONTENT_HAS_BEEN_DELETED, "Attempt to save a deleted content with content_id = {$this->content_id}");
         throw new PAException(CONTENT_HAS_BEEN_DELETED, "Object you are trying to save has been deleted");
     }
     Logger::log(" Enter: Content::save()", LOGGER_INFO);
     try {
         if (empty($this->active)) {
             $this->active = 1;
         }
         // before saving, check if content already exists or not.
         if ($this->content_id) {
             // UPDATE if exists
             if ($this->parent_collection_id != -1) {
                 //FIXME: do we need to make the distinction here?  Should probably always be able to set collection_id, even if -1.
                 $sql = "UPDATE {contents} SET title = ?, is_active = ?, body = ?, allow_comments =?, changed = ?, trackbacks = ?, collection_id = ?, is_html = ? WHERE content_id = ? AND is_active = ?";
                 $res = Dal::query($sql, array($this->title, $this->is_active, $this->body, $this->allow_comments, time(), $this->trackbacks, $this->parent_collection_id, $this->is_html, $this->content_id, $this->is_active));
             } else {
                 $sql = "UPDATE {contents} SET title = ?, is_active = ?, body = ?, allow_comments =?, changed = ?, trackbacks = ?, is_html = ? WHERE content_id = ? AND is_active = ?";
                 $res = Dal::query($sql, array($this->title, $this->is_active, $this->body, $this->allow_comments, time(), $this->trackbacks, $this->is_html, $this->content_id, $this->is_active));
             }
         } else {
             // get next ID for content.
             $this->content_id = Dal::next_id('Content');
             $this->created = time();
             $this->changed = $this->created;
             if (!$this->allow_comments) {
                 $this->allow_comments = 0;
             }
             $sql = "INSERT INTO {contents} (content_id, author_id, type, title, is_active, body, allow_comments, collection_id, created, changed, trackbacks, display_on, is_html) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
             $res = Dal::query($sql, array($this->content_id, $this->author_id, $this->type, $this->title, $this->is_active, $this->body, $this->allow_comments, $this->parent_collection_id, $this->created, $this->changed, $this->trackbacks, $this->display_on, $this->is_html));
         }
         if ($this->is_default_content == FALSE) {
             Content::save_recent_content($this->content_id, $this->type);
         }
         // if everything succeeded, commit
         Dal::commit();
     } catch (Exception $e) {
         Logger::log("Exception occurred inside Content::save(); rolling back", LOGGER_INFO);
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: Content::save()", LOGGER_INFO);
     return $this->content_id;
 }
 /**
  * Save the user data to the database
  *
  * When creating a new user, set all the attributes for the user (except user_id) and call save. Save will
  * set the user_id for the user.
  *
  */
 public function save($check_unique_email = true)
 {
     Logger::log("Enter: function User::save");
     // global var $_base_url has been removed - please, use PA::$url static variable
     $sql = '';
     try {
         if (!$this->login_name || !$this->password || !$this->first_name || !$this->email) {
             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_active) {
             Logger::log("Throwing exception SAVING_DELETED_USER | Message: Saving a deleted user is not allowed", LOGGER_ERROR);
             throw new PAException(SAVING_DELETED_USER, "Saving a deleted user is not allowed");
         }
         // added to remove unnecessary check whether the word begins or ends with a 'space' character
         $this->first_name = @trim($this->first_name);
         $this->last_name = @trim($this->last_name);
         $this->login_name = @trim($this->login_name);
         $this->password = @trim($this->password);
         $this->email = @trim($this->email);
         // checking the user data When creating a new user or updating the existing user value
         $this->check_authenticated_user_data();
         if ($this->is_new) {
             // Make sure that the login name is unique.
             $sql = 'SELECT * FROM {users} WHERE login_name = ? AND is_active <> ? AND is_active <> ?';
             $data = array($this->login_name, DELETED, UNVERIFIED);
             $res = Dal::query($sql, $data);
             if ($res->numRows() > 0) {
                 Logger::log(" Throwing exception USER_LOGINNAME_TAKEN | Message: This Login name has already been taken", LOGGER_ERROR);
                 throw new PAException(USER_LOGINNAME_TAKEN, "This Login name has already been taken");
             }
             if ($check_unique_email) {
                 // make sure that the email address is unique
                 $sql = 'SELECT * FROM {users} WHERE email = ? AND is_active <> ?';
                 $data = array($this->email, DELETED);
                 $res = Dal::query($sql, $data);
                 if ($res->numRows() > 0) {
                     Logger::log(" Throwing exception USER_EMAIL_NOT_UNIQUE | Message: Email address must be unique", LOGGER_ERROR);
                     throw new PAException(USER_EMAIL_NOT_UNIQUE, "Email address that you have given is already taken please give another email address");
                 }
             }
             $this->user_id = Dal::next_id("User");
             if ($this->api_call != true) {
                 // only encrypt the password if this is not an API call
                 $this->password = md5($this->password);
             }
             if (!isset($this->created)) {
                 $this->created = time();
             }
             $this->changed = $this->created;
             $this->last_login = time();
             if ($this->api_call == true) {
                 $sql = 'INSERT into {users} (user_id, core_id, login_name, password, first_name, last_name, email, is_active, created, changed, picture, picture_width, picture_height, avatar, avatar_width, avatar_height, avatar_small, avatar_small_width, avatar_small_height, last_login) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? , ?, ?, ?, ?, ?)';
                 $data = array($this->user_id, $this->core_id, $this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, $this->is_active, $this->created, $this->changed, $this->picture, $this->picture_dimensions['width'], $this->picture_dimensions['height'], $this->avatar, $this->avatar_dimensions['width'], $this->avatar_dimensions['height'], $this->avatar_small, $this->avatar_small_dimensions['width'], $this->avatar_small_dimensions['height'], $this->last_login);
             } else {
                 $sql = 'INSERT into {users} (user_id, login_name, password, first_name, last_name, email, is_active, created, changed, picture, last_login) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
                 $data = array($this->user_id, $this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, $this->is_active, $this->created, $this->changed, $this->picture, $this->last_login);
             }
             Dal::query($sql, $data);
             // Code for sending the data to ping server: begin
             $PingClient = new PingClient();
             global $host;
             // defined in config.inc
             // global var $path_prefix has been removed - please, use PA::$path static variable
             $pa_url = $host;
             $pa_activity = PA_ACTIVITY_USER_ADDED;
             $pa_user_url = PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $this->user_id;
             $pa_user_name = $this->first_name . ' ' . $this->last_name;
             $param_array = array('pa_url' => $pa_url, 'pa_activity' => $pa_activity, 'pa_user_url' => $pa_user_url, 'pa_user_name' => $pa_user_name);
             $PingClient->set_params($param_array);
             // @$PingClient->send_ping();
             // Code for sending the data to ping server: end
             // By default first user is being assigned as ADMIN (admin role id is 2).
             if ($this->user_id == SUPER_USER_ID) {
                 $user_roles = array();
                 $user_roles[0] = array('role_id' => ADMINISTRATOR_ROLE, 'extra' => serialize(array('user' => false, 'network' => true, 'groups' => array())));
                 $this->set_user_role($user_roles);
             }
         } else {
             if ($check_unique_email) {
                 // make sure that the email address is unique
                 $sql = 'SELECT * FROM {users} WHERE email = ?';
                 $data = array($this->email);
                 $res = Dal::query($sql, $data);
                 if ($res->numRows() > 0) {
                     $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                     if ($row->user_id != $this->user_id) {
                         Logger::log(" Throwing exception USER_EMAIL_NOT_UNIQUE | Message: Email address must be unique", LOGGER_ERROR);
                         throw new PAException(USER_EMAIL_NOT_UNIQUE, "Email address that you have given is already taken please give another email address");
                     }
                 }
             }
             if ($this->api_call == true) {
                 $sql = 'UPDATE {users} SET login_name = ?, password = ?, first_name = ?, last_name = ?, email = ?, is_active = ?, changed = ?, picture = ?, picture_width = ?, picture_height = ?, avatar = ?, avatar_width = ?, avatar_height = ?, avatar_small = ?, avatar_small_width = ?, avatar_small_height = ? WHERE user_id = ?';
                 $data = array($this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, 1, time(), $this->picture, $this->picture_dimensions['width'], $this->picture_dimensions['height'], $this->avatar, $this->avatar_dimensions['width'], $this->avatar_dimensions['height'], $this->avatar_small, $this->avatar_small_dimensions['width'], $this->avatar_small_dimensions['height'], $this->user_id);
             } else {
                 $sql = 'UPDATE {users} SET login_name = ?, password = ?, first_name = ?, last_name = ?, email = ?, is_active = ?, changed = ?, picture = ? WHERE user_id = ?';
                 $data = array($this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, 1, time(), $this->picture, $this->user_id);
             }
             Dal::query($sql, $data);
         }
         // all done - commit to database
         Dal::commit();
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     // save the core user data so that search can find it
     $data = array();
     $data['first_name'] = $this->first_name;
     $data['last_name'] = $this->last_name;
     $data['email'] = $this->email;
     $data['login_name'] = $this->login_name;
     $old_data = User::load_user_profile($this->user_id, $this->user_id, BASIC, null);
     // ensure we are NOT duplicating data here!!
     foreach ($old_data as $i => $d) {
         $k = $d['name'];
         $v = $d['value'];
         if (empty($data[$k])) {
             // only ever preserve if we are NOT submiting this field
             $data[$k] = $v;
         }
     }
     // turn it all to a format that this function undersatbds
     $user_data = array();
     foreach ($data as $k => $v) {
         $user_data[] = array('name' => $k, 'value' => $v, 'uid' => $this->user_id, 'perm' => 1, 'type' => BASIC);
     }
     $this->save_user_profile($user_data, BASIC);
     $this->is_new = FALSE;
     if ($this->tags) {
         // Attach an array of string tags to the user
         //Tag::add_tags_to_user($this->user_id, $this->tags);
     }
     Logger::log("Exit: function User::save");
 }
Exemple #6
0
 /**
  * Adds the given message for the given user id.
  *
  * @param integer $sender_id The id of the user who sends the message to be added.
  * @param integer $recipients_ids The ids of the recipients of the message to be added.
  * @param string represents all the recipients of a message.
  * @param string subject of message.
  * @param text body of the message.
  */
 static function add_message($sender_id, $recipients_ids = NULL, $all_recipients, $subject, $body, $is_draft = FALSE, $in_reply_to = 0)
 {
     Logger::log("Enter: function Message::add_message()");
     //if all recipient is an array not a comma separated string
     if (is_array($all_recipients)) {
         $user_names = $all_recipients;
         $all_recipients = implode(",", $user_names);
     } else {
         //if all recipient is a comma separated string
         // use preg_split here, as the list might include spaces, but the names will not
         $user_names = preg_split("/,\\s*/", $all_recipients);
     }
     // If recipients array is not set from the arguments only then it will be set here.
     if (empty($recipients_ids)) {
         foreach ($user_names as $user_name) {
             $user = new User();
             $user->load(trim($user_name));
             $recipients_ids[] = $user->user_id;
         }
     }
     $message_id = Dal::next_id('Message');
     // see if we are part of a conversation
     if ($in_reply_to > 0) {
         $conversation_id = Message::get_conversation_id($in_reply_to);
     } else {
         $conversation_id = $message_id;
         // this would be the parent of any subsequent conversations
     }
     $sql = 'INSERT into {private_messages} (message_id, sender_id, all_recipients, subject, body, sent_time, size, in_reply_to, conversation_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $data = array($message_id, $sender_id, $all_recipients, $subject, $body, time(), ceil(strlen($body) / 1024), $in_reply_to, $conversation_id);
     Dal::query($sql, $data);
     Logger::log("Saved private message ID {$message_id}, from {$sender_id} to recipient(s): {$all_recipients}", LOGGER_ACTION);
     foreach ($recipients_ids as $id) {
         $folder_name = $is_draft ? DRAFT : INBOX;
         $folder_id = Message::get_folder_by_name($id, $folder_name);
         $sql = 'INSERT into {user_message_folder} (mid, fid, new_msg, reply, forward) values (?, ?, ?, ?, ?)';
         $data = array($message_id, $folder_id, 1, 0, 0);
         Dal::query($sql, $data);
         Logger::log("Linked message ID {$message_id} to folder {$folder_id} ({$folder_name}) for user {$id}", LOGGER_ACTION);
     }
     if ($is_draft == FALSE) {
         $sent_folder_name = SENT;
         $folder_id = Message::get_folder_by_name($sender_id, $sent_folder_name);
         $sql = 'INSERT into {user_message_folder} (mid, fid, new_msg, reply, forward) values (?, ?, ?, ?, ?)';
         $data = array($message_id, $folder_id, 1, 0, 0);
         Dal::query($sql, $data);
         Logger::log("Linked message ID {$message_id} to folder {$folder_id} ({$sent_folder_name}) for sender {$sender_id}", LOGGER_ACTION);
     }
     Logger::log("Exit: function Message::add_message()");
     return;
 }
 /**
  * saves data to database
  * @access protected
  */
 public function save()
 {
     Logger::log("Enter: ContentCollection::save()");
     // If same TITLE value exist for same author
     if ($this->collection_id) {
         $sql = "SELECT collection_id FROM {contentcollections} WHERE collection_id NOT IN ('{$this->collection_id}')  AND author_id = ? AND title = ? AND is_active = ?";
         $data = array($this->author_id, $this->title, 1);
     } else {
         if ($this->type == 1) {
             $sql = "SELECT collection_id FROM {contentcollections} WHERE author_id = ? AND title = ? AND is_active = ?";
         } else {
             if ($this->type == 2) {
                 $sql = "SELECT collection_id, album_type_id FROM {contentcollections} AS CC, {contentcollections_albumtype} AS CCA WHERE CC.author_id = ? AND CC.title = ? AND CC.collection_id = CCA.contentcollection_id AND CCA.album_type_id = {$this->album_type} AND is_active = ?";
             }
         }
         $data = array($this->author_id, $this->title, 1);
     }
     $res = Dal::query($sql, $data);
     if ($res->numRows() > 0) {
         if ($this->type == 1) {
             $colletion_name = "group";
         } else {
             $colletion_name = "album";
         }
         Logger::log("Throwing Exception CONTENT_COLLECTION_TITLE_ALREADY_EXIST", LOGGER_ERROR);
         throw new PAException(CONTENT_COLLECTION_TITLE_ALREADY_EXIST, "Error: This {$colletion_name} name already exist");
     }
     //If exists then update else insert
     if ($this->collection_id) {
         $sql = "UPDATE {contentcollections} SET type = ?, author_id = ?, title = ?, description = ?, changed =?, picture = ? WHERE collection_id = ?";
         $data = array($this->type, $this->author_id, $this->title, $this->description, time(), $this->picture, $this->collection_id);
         $res = Dal::query($sql, $data);
     } else {
         // get id
         $this->collection_id = Dal::next_id("ContentCollection");
         $this->created = time();
         $this->changed = time();
         $this->is_active = 1;
         $sql = "INSERT INTO {contentcollections} (collection_id, author_id, type, title, description, is_active, created, changed, picture) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
         $data = array($this->collection_id, $this->author_id, $this->type, $this->title, $this->description, $this->is_active, $this->created, $this->changed, $this->picture);
         $res = Dal::query($sql, $data);
     }
     Logger::log("Exit: ContentCollection::save()");
     return;
 }
 /**
  * Save the persona property data to the database.
  *
  * When creating a new persona property, set all the attributes for the 
  * property (except persona_property_id) and call save. Save will set
  * the persona_propety_id for the persona.
  */
 public function save()
 {
     Logger::log("Enter: function PersonaProperty::save");
     try {
         if (!$this->persona_id || !$this->name) {
             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;
             $this->persona_property_id = Dal::next_id("persona_properties");
             $sql = 'INSERT INTO {persona_properties} (parent_id, persona_id, name, content, content_type, content_hash, serial_number, last_update, category, viewer) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
             $data = array($this->parent_id, $this->persona_id, $this->name, $this->content, $this->content_type, $this->content_hash, $this->serial_number, $this->last_update, $this->category, $this->viewer);
             Dal::query($sql, $data);
         } else {
             $sql = "UPDATE {persona_properties} SET parent_id = ?, persona_id = ?, name = ?, content = ?, content_type = ?, content_hash = ?, serial_number = ?, last_update = ?, category = ?, viewer = ? WHERE persona_property_id = ?";
             $data = array($this->parent_id, $this->persona_id, $this->name, $this->content, $this->content_type, $this->content_hash, $this->serial_number, $this->last_update, $this->category, $this->viewer, $this->persona_property_id);
             Dal::query($sql, $data);
         }
         // All done - commit to database.
         Dal::commit();
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: function PersonaProperty::save");
 }
Exemple #9
0
 /**
  * Save the user data to the database
  *
  * When creating a new user, set all the attributes for the user (except user_id) and call save. Save will
  * set the user_id for the user.
  *
  */
 public function save()
 {
     Logger::log("Enter: function User::save");
     global $base_url;
     $sql = '';
     try {
         if (!$this->login_name || !$this->password || !$this->first_name || !$this->email) {
             Logger::log("User::save Throwing exception REQUIRED_PARAMETERS_MISSING | Message: Required parameters missing", LOGGER_ERROR);
             throw new PAException(REQUIRED_PARAMETERS_MISSING, "Required parameters missing: login_name:{$this->login_name}, password:{$this->password}, first_name:{$this->first_name}, email:{$this->email}");
         }
         if (!$this->is_active) {
             Logger::log("Throwing exception SAVING_DELETED_USER | Message: Saving a deleted user is not allowed", LOGGER_ERROR);
             throw new PAException(SAVING_DELETED_USER, "Saving a deleted user is not allowed");
         }
         // checking the user data When creating a new user or updating the existing user value
         $this->check_authenticated_user_data();
         if ($this->is_new) {
             // Make sure that the login name is unique.
             $sql = 'SELECT * FROM {users} WHERE login_name = ? AND is_active <> ? AND is_active <> ?';
             $data = array($this->login_name, DELETED, UNVERIFIED);
             $res = Dal::query($sql, $data);
             if ($res->numRows() > 0) {
                 Logger::log(" Throwing exception USER_LOGINNAME_TAKEN | Message: This Login name has already been taken", LOGGER_ERROR);
                 throw new PAException(USER_LOGINNAME_TAKEN, "This Login name has already been taken");
             }
             // make sure that the email address is unique
             $sql = 'SELECT * FROM {users} WHERE email = ? AND is_active <> ?';
             $data = array($this->email, DELETED);
             $res = Dal::query($sql, $data);
             if ($res->numRows() > 0) {
                 Logger::log(" Throwing exception USER_EMAIL_NOT_UNIQUE | Message: Email address must be unique", LOGGER_ERROR);
                 throw new PAException(USER_EMAIL_NOT_UNIQUE, "Email address that you have given is already taken please give another email address");
             }
             $this->user_id = Dal::next_id("User");
             $this->password = md5($this->password);
             $this->created = time();
             $this->changed = $this->created;
             $this->last_login = $this->created;
             $sql = 'INSERT into {users} (user_id, login_name, password, first_name, last_name, email, is_active, created, changed, picture, last_login) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
             $data = array($this->user_id, $this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, $this->is_active, $this->created, $this->changed, $this->picture, $this->last_login);
             Dal::query($sql, $data);
             // Code for sending the data to ping server: begin
             $PingClient = new PingClient();
             global $host;
             // defined in config.inc
             global $path_prefix;
             $pa_url = $host;
             $pa_activity = PA_ACTIVITY_USER_ADDED;
             $pa_user_url = $base_url . '/user.php?uid=' . $this->user_id;
             $pa_user_name = $this->first_name . ' ' . $this->last_name;
             $param_array = array('pa_url' => $pa_url, 'pa_activity' => $pa_activity, 'pa_user_url' => $pa_user_url, 'pa_user_name' => $pa_user_name);
             $PingClient->set_params($param_array);
             // @$PingClient->send_ping();
             // Code for sending the data to ping server: end
             // By default first user is being assigned as ADMIN (admin role id is 2).
             if ($this->user_id == 1) {
                 $user_role = array(2);
                 $this->set_user_role($user_role);
             }
         } else {
             // make sure that the email address is unique
             $sql = 'SELECT * FROM {users} WHERE email = ?';
             $data = array($this->email);
             $res = Dal::query($sql, $data);
             if ($res->numRows() > 0) {
                 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
                 if ($row->user_id != $this->user_id) {
                     Logger::log(" Throwing exception USER_EMAIL_NOT_UNIQUE | Message: Email address must be unique", LOGGER_ERROR);
                     throw new PAException(USER_EMAIL_NOT_UNIQUE, "Email address that you have given is already taken please give another email address");
                 }
             }
             $sql = 'UPDATE {users} SET login_name = ?, password = ?, first_name = ?, last_name = ?, email = ?, is_active = ?, changed = ?, picture = ? WHERE user_id = ?';
             $data = array($this->login_name, $this->password, $this->first_name, $this->last_name, $this->email, 1, time(), $this->picture, $this->user_id);
             Dal::query($sql, $data);
         }
         // all done - commit to database
         Dal::commit();
     } catch (PAException $e) {
         Dal::rollback();
         throw $e;
     }
     $this->is_new = FALSE;
     if ($this->tags) {
         // Attach an array of string tags to the user
         //Tag::add_tags_to_user($this->user_id, $this->tags);
     }
     Logger::log("Exit: function User::save");
 }
 /**
  * saves data to database
  * @access protected
  */
 public function save()
 {
     Logger::log("Enter: ContentCollection::save()");
     // If same TITLE value exist for same author
     if (empty($this->author_id)) {
         Logger::log('Exit: ContentCollection::save(). Author of the collection is not specified.');
         throw new CNException(BAD_PARAMETER, 'Author of the collection is not specified.');
     }
     $sql = NULL;
     $data = array($this->author_id, $this->title, $this->is_active);
     if (!empty($this->collection_id)) {
         array_push($data, $this->collection_id);
         $sql = 'SELECT collection_id FROM {contentcollections} WHERE author_id = ? AND title = ? AND is_active = ? AND collection_id <> ?';
     } else {
         if (empty($this->type)) {
             Logger::log('Exit: ContentCollection::save(). Collection type is not specified.');
             throw new CNException(BAD_PARAMETER, 'Collection type is not specified.');
         } else {
             if ($this->type == 2) {
                 //TODO: Code refining is pending for the album contentcollection.
                 $sql = "SELECT collection_id, album_type_id FROM {contentcollections} AS CC, {contentcollections_albumtype} AS CCA WHERE CC.author_id = ? AND CC.title = ? AND CC.collection_id = CCA.contentcollection_id AND CCA.album_type_id = {$this->album_type} AND is_active = ?";
             } else {
                 array_push($data, $this->type);
                 $sql = 'SELECT collection_id FROM {contentcollections} WHERE author_id = ? AND title = ? AND is_active = ? AND type = ?';
             }
         }
     }
     $res = Dal::query($sql, $data);
     //TODO: Need to remove the following code. Base call should not dependent on the child classes.
     if ($res->numRows() > 0) {
         if ($this->type == 1) {
             $colletion_name = "group";
         } else {
             $colletion_name = "album";
         }
         Logger::log("Throwing Exception CONTENT_COLLECTION_TITLE_ALREADY_EXIST", LOGGER_ERROR);
         throw new CNException(CONTENT_COLLECTION_TITLE_ALREADY_EXIST, "Error: This {$colletion_name} name already exist");
     }
     //If collection_id exists then update else insert
     if ($this->collection_id) {
         $sql = "UPDATE {contentcollections} SET type = ?, author_id = ?, title = ?, description = ?, changed =?, picture = ? WHERE collection_id = ?";
         $data = array($this->type, $this->author_id, $this->title, $this->description, time(), $this->picture, $this->collection_id);
         $res = Dal::query($sql, $data);
     } else {
         // get id
         $this->collection_id = Dal::next_id("ContentCollection");
         $this->created = time();
         $this->changed = time();
         $this->is_active = 1;
         $sql = "INSERT INTO {contentcollections} (collection_id, author_id, type, title, description, is_active, created, changed, picture) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
         $data = array($this->collection_id, $this->author_id, $this->type, $this->title, $this->description, $this->is_active, $this->created, $this->changed, $this->picture);
         $res = Dal::query($sql, $data);
     }
     Logger::log("Exit: ContentCollection::save()");
     return;
 }