Example #1
0
 function getSharedWithNames($list_id)
 {
     $shared_list = new SharedList();
     $user = new User();
     $user_data = [];
     $data = $shared_list->getSharedWith($list_id);
     foreach ($data as $index => $list) {
         $user_data[$index] = $user->show('user_id', $list['viewer_id']);
     }
     return $user_data;
 }
Example #2
0
 public function login()
 {
     if (post('login')) {
         $login = ['username' => post('username'), 'password' => md5(post('password'))];
         if ($user = User::show($login)->fetchOne()) {
             $login = ['auth' => 1, 'id' => $user->id_pengguna, 'username' => $user->username, 'level' => $user->level];
             if ($user->level !== 1) {
                 $pelanggan = Customer::show(['id_pengguna' => $user->id_pengguna])->fetchOne();
                 $login['id_pelanggan'] = $pelanggan->id_pelanggan;
             }
             session($login);
             redirect('admin-shop/orders');
         } else {
             set_alert('error', 'Login gagal');
         }
     }
     return $this->render('form-login', ['heading' => 'Silahkan login']);
 }
Example #3
0
 public function users($do = '', $id = '')
 {
     $data = ['heading' => 'Administrasi: Pengguna'];
     switch ($do) {
         case 'form':
             if (post('submit')) {
                 $data = ['username' => post('username'), 'email' => post('email')];
                 if (User::is('admin')) {
                     $data['level'] = post('level');
                 }
                 if ($password = post('password') and $password == post('passconf')) {
                     $data['password'] = $password;
                 }
                 if (User::save($data, $id)) {
                     if ($id) {
                         set_alert('success', 'Berhasil memperbarui data pengguna <b>' . $data['username'] . '</b>');
                     } else {
                         set_alert('success', 'Berhasil menambahkan <b>' . $data['username'] . '</b> sebagai pengguna');
                     }
                     return redirect('admin/users');
                 }
                 set_alert('error', 'Terjadi kesalahan dalam penyimpanan pengguna <b>' . $data['username'] . '</b>');
                 return redirect($this->uri->path());
             }
             if ($id) {
                 $data['data'] = User::show([User::primary() => $id])->fetchOne();
             }
             return $this->render('user-form', $data);
             break;
         case 'delete':
             if (User::del([User::primary() => $id])) {
                 set_alert('success', 'Pengguna berhasil terhapus');
             } else {
                 set_alert('error', 'Terjadi kesalahan dalam penghapusan pengguna');
             }
             return redirect('admin/users');
             break;
         default:
             $data['data'] = User::show();
             return $this->render('user-table', $data);
             break;
     }
 }
Example #4
0
 /**
  * 直接向当前用户的博客源删除一个数据
  * 
  * @param sting $path    路径
  * @param sting $message 注释
  * 
  * @return \stdClass
  */
 public static function destroyUserRespos($path, $message)
 {
     $user = User::show();
     $login = $user['metadata']['login'];
     $repo = Github::showDefaultBlogRepoName($user['metadata']['login']);
     $respositories = new \Api\Github\Respositories();
     return $respositories->delete($login, $repo, $path, $message);
 }
Example #5
0
require_once ROOT_NAME . "/classes/Tweet.php";
require_once ROOT_NAME . "/classes/User.php";
require_once ROOT_NAME . "/classes/TweetsLoader.php";
require_once ROOT_NAME . "/classes/Database.php";
$db = Database::getInstance();
$conn = $db->getConnection();
$loader = new TweetsLoader($conn);
$loader->loadTweets();
$tweetArray = $loader->getArrayWithTweets();
foreach ($tweetArray as $tweet) {
    $userId = $tweet->getUserId();
    $user = new User($conn);
    $user->loadFromDb($userId);
    $tweetId = $tweet->getId();
    $comments = $tweet->loadAllComments();
    echo "<div class='col-md-12 container tweet-block'>";
    $user->show();
    $tweet->show();
    require ROOT_NAME . "/includes/commentForm.php";
    echo "<ul class='comments'>";
    foreach ($comments as $comment) {
        echo "<li>";
        $comment->show();
        $commenter = new User($conn);
        $commenter->loadFromDb($comment->getUserId());
        $commenter->show();
        echo "</li>";
    }
    echo "</ul>";
    echo "</div>";
}
Example #6
0
 public function __construct()
 {
     // check for messages
     if (isset($_SESSION['confirm_message'])) {
         $cf_msg = $_SESSION['confirm_message'];
         $_SESSION['confirm_message'] = null;
     }
     $user_model = new User();
     $list_model = new Lists();
     $item_model = new Item();
     $note_model = new Note();
     $contact_model = new Contact();
     $shared_list_model = new SharedList();
     $user_data = $user_model->show('user_id', $_SESSION['id']);
     $list_data = $list_model->showAll('user_id', $_SESSION['id']);
     $item_data = $item_model->showAll('user_id', $_SESSION['id']);
     $note_data = $note_model->showAll('user_id', $_SESSION['id']);
     // GET CONTACT DATA
     $contact_data = $contact_model->showAll('user_id', $_SESSION['id']);
     $contacts = [];
     foreach ($contact_data as $index => $contact) {
         $contacts[$index] = $user_model->show('user_id', $contact_data[$index]['contact_id']);
     }
     // GET SHARED LIST DATA FOR THE USERS LISTS
     $shared_list_data = $shared_list_model->showAll('user_id', $_SESSION['id']);
     // GET NAMES FOR WHOM THE USER IS SHARING LISTS WITH
     foreach ($list_data as $list) {
         $shared_lists_names = $list_model->getSharedWithNames($list['list_id']);
     }
     // DATA FOR THE LISTS BEING SHARED WITH THE USER
     $shared_lists_id = $shared_list_model->getSharedLists($_SESSION['id']);
     $shared_with_id = [];
     $shared_lists_info = [];
     $items_from_shared_lists = [];
     foreach ($shared_lists_id as $index => $shared_list) {
         $shared_lists_info[$index] = $list_model->show('list_id', $shared_lists_id[$index]['list_id']);
         $shared_with_id[$index] = $shared_list_model->getSharedWith($shared_lists_id[$index]['list_id']);
         $items_from_shared_lists[$index] = $item_model->showAll('list_id', $shared_lists_id[$index]['list_id']);
     }
     $shared_item_info = [];
     foreach ($items_from_shared_lists as $item_array) {
         foreach ($item_array as $item) {
             array_push($shared_item_info, $item);
         }
     }
     //find who each shared lists is being shared with
     $shared_with_names = [];
     $user_num = 0;
     foreach ($shared_with_id as $shared_with) {
         for ($i = 0; $i < count($shared_with); $i++) {
             $shared_with_names[$user_num] = $user_model->showAll('user_id', $shared_with[$i]['viewer_id']);
             $user_num++;
         }
     }
     // GET SHARED NOTE DATA
     $shared_note_info = [];
     $note_num = 0;
     foreach ($shared_item_info as $item) {
         $shared_note_info[$note_num] = $note_model->showAll('item_id', $item['item_id']);
         $note_num++;
     }
     $shared_note_data = [];
     foreach ($shared_note_info as $shared_note) {
         foreach ($shared_note as $note) {
             array_push($shared_note_data, $note);
         }
     }
     // end note loop
     $page = "dashboard";
     $profile_pic_path = 'users/' . $user_data['user_id'] . '/img/profilepic.jpg';
     require_once 'views/dashboardview.php';
 }