/**
  * Delete avatar from Avatar Gallery
  * @param   int     $avatar_id      Avatar ID
  * @return  boolean TRUE on success or FALSE on error
  */
 function deleteGalleryAvatar($avatar_id = 0)
 {
     $result = false;
     _pcpin_loadClass('binaryfile');
     $binaryfile = new PCPIN_BinaryFile($this);
     if (!empty($avatar_id) && $this->_db_getList('binaryfile_id,primary', 'id = ' . $avatar_id, 'user_id = 0', 1)) {
         // Avatar exists
         $binaryfile_id = $this->_db_list[0]['binaryfile_id'];
         $default = 'y' === $this->_db_list[0]['primary'];
         $this->_db_freeList();
         if ($default) {
             // Default avatar will be deleted. Check wether there are not default avatars.
             if ($this->_db_getList('id,binaryfile_id', 'user_id = 0', 'primary = n', 1)) {
                 $new_default_id = $this->_db_list[0]['id'];
                 $new_default_binaryfile_id = $this->_db_list[0]['binaryfile_id'];
                 $this->_db_freeList();
             } else {
                 // Last gallery avatar cannot be deleted!
                 return false;
             }
         }
         // Check wether avatar is linked to other users
         $linked_avatars = array();
         if ($this->_db_getList('id,user_id,primary', 'binaryfile_id = ' . $binaryfile_id, 'user_id > 0')) {
             // There are some linked avatars
             $linked_avatars = $this->_db_list;
             $this->_db_freeList();
             if (empty($default)) {
                 // Get default avatar
                 $this->_db_getList('binaryfile_id', 'user_id = 0', 'primary = y', 1);
                 $new_default_binaryfile_id = $this->_db_list[0]['binaryfile_id'];
             }
         }
         if ($default) {
             // Set new default avatar
             $this->setDefaultAvatarGallery($new_default_id);
         }
         // Update linked avatars
         foreach ($linked_avatars as $data) {
             // Check wether user has other avatars
             $old_id = $data['id'];
             if ($data['primary'] == 'y') {
                 // That was user's primary avatar
                 if ($this->_db_getList('id', 'user_id = ' . $data['user_id'], 'id != ' . $old_id, 1)) {
                     // Set new primary avatar
                     $this->setPrimaryAvatar($data['user_id'], $this->_db_list[0]['id']);
                 }
             }
             $this->_db_deleteRow($old_id);
         }
         // Delete binary file
         $binaryfile->deleteBinaryFile($binaryfile_id);
         // Delete avatar
         $this->_db_deleteRow($avatar_id);
         $result = true;
     }
     return $result;
 }
 /**
  * Delete attachment
  * @param   int       $id               Optional. Attachment ID
  * @param   int       $message_id       Optional. Message ID
  * @return  boolean TRUE on success or FALSE on error
  */
 function deleteAttachment($id = 0, $message_id = 0)
 {
     $result = false;
     _pcpin_loadClass('binaryfile');
     $binaryfile = new PCPIN_BinaryFile($this);
     if (!empty($id) && $this->_db_getList('binaryfile_id', 'id = ' . $id, 1)) {
         $result = true;
         $binaryfile->deleteBinaryFile($this->_db_list[0]['binaryfile_id']);
         $this->_db_deleteRow($id);
     } elseif (!empty($message_id) && $this->_db_getList('id,binaryfile_id', 'message_id = ' . $message_id)) {
         $result = true;
         $ids = $this->_db_list;
         foreach ($ids as $data) {
             $binaryfile->deleteBinaryFile($data['binaryfile_id']);
             $this->_db_deleteRow($data['id']);
         }
     }
     $this->_db_freeList();
     return $result;
 }
                        if ($tmpdata->_db_getList('binaryfile_id', 'user_id = ' . $session->_s_user_id, 'type = 1', 1)) {
                            // New image uploaded
                            $binaryfile_id = $tmpdata->_db_list[0]['binaryfile_id'];
                            $tmpdata->_db_freeList();
                        } elseif ($room_data['background_image'] == $image) {
                            $binaryfile_id = $image;
                        } else {
                            $binaryfile_id = 0;
                        }
                    } else {
                        $binaryfile_id = 0;
                    }
                    $tmpdata->deleteUserRecords($session->_s_user_id, 1, 0, true);
                    $xmlwriter->setHeaderStatus(0);
                    $xmlwriter->setHeaderMessage($l->g('changes_saved'));
                    $room_password = null;
                    if (!empty($password_protect) && !empty($change_password)) {
                        $room_password = md5(base64_decode($password));
                    } elseif (empty($password_protect)) {
                        $room_password = '';
                    }
                    if (empty($binaryfile_id) && !empty($room_data['background_image'])) {
                        // Delete old image
                        $binaryfile->deleteBinaryFile($room_data['background_image']);
                    }
                    $room->updateRoom($room_id, false, true, null, $name, $category_id, $description, null, $default_message_color, $room_password, $binaryfile_id);
                }
                break;
        }
    }
}
 /**
  * Delete smilie
  * @param   int   $id     Smilie ID
  * @return  boolean   TRUE on success or FALSE on error
  */
 function deleteSmilie($id)
 {
     $result = false;
     if (!empty($id) && $this->_db_getList('binaryfile_id', 'id =# ' . $id, 1)) {
         $result = true;
         $binaryfile_id = $this->_db_list[0]['binaryfile_id'];
         $this->_db_freeList();
         // Delete binary file
         _pcpin_loadClass('binaryfile');
         $binaryfile = new PCPIN_BinaryFile($this);
         $binaryfile->deleteBinaryFile($binaryfile_id);
         // Delete smilie
         $this->_db_deleteRow($id);
     }
     return $result;
 }
Пример #5
0
 /**
  * Delete room
  * @param   int       $id       Room ID
  * @return  boolean TRUE on success or FALSE on error
  */
 function deleteRoom($id = 0)
 {
     $result = false;
     if (!empty($id) && $this->_db_getList('background_image', 'id = ' . $id, 1)) {
         if ($result = $this->_db_deleteRow($id)) {
             _pcpin_loadClass('binaryfile');
             $binaryfile = new PCPIN_BinaryFile($this);
             $binaryfile->deleteBinaryFile($this->_db_list[0]['background_image']);
         }
         $this->_db_freeList();
         // Update "moderated_rooms" field by category and room moderators
         $moderators = $this->getModerators($id);
         if (!empty($moderators)) {
             _pcpin_loadClass('user');
             $user = new PCPIN_User($this);
             foreach ($moderators as $data) {
                 $user->_db_updateRow($data['id'], 'id', array('moderated_rooms' => trim(str_replace(',' . $id . ',', ',', ',' . $data['moderated_rooms'] . ','), ',')));
             }
         }
     }
     return $result;
 }
 /**
  * Delete all records owned by user
  * @param   int       $user_id          Avatar owner' User ID
  * @param   int       $type             Optional. Data type.
  * @param   int       $binaryfile_id    Optional. Binaryfile ID.
  * @param   boolean   $keep_binary      Optional. If TRUE, then binaryfile will be not deleted.
  */
 function deleteUserRecords($user_id = 0, $type = 0, $binaryfile_id = 0, $keep_binary = false)
 {
     _pcpin_loadClass('binaryfile');
     $binaryfile = new PCPIN_BinaryFile($this);
     if (!empty($user_id)) {
         if (empty($type)) {
             $this->_db_getList('id,binaryfile_id', 'user_id = ' . $user_id);
         } else {
             $this->_db_getList('id,binaryfile_id', 'user_id = ' . $user_id, 'type = ' . $type);
         }
         if (!empty($this->_db_list)) {
             $list = $this->_db_list;
             $this->_db_freeList();
             foreach ($list as $data) {
                 if (empty($binaryfile_id) || $binaryfile_id == $data['binaryfile_id']) {
                     if (true !== $keep_binary) {
                         // Delete binary file
                         $binaryfile->deleteBinaryFile($data['binaryfile_id']);
                     }
                     // Delete record
                     $this->_db_deleteRow($data['id']);
                 }
             }
         }
     }
 }