protected function addpost()
 {
     //$post
     global $rep, $view;
     $data = array();
     if (isset($_POST['addpost'])) {
         //we edit
         $post_title = isset($_POST['post_title']) ? $_POST['post_title'] : NULL;
         $post_content = isset($_POST['post_content']) ? $_POST['post_content'] : NULL;
         $data['uploadfile'] = NULL;
         $usr = $_SESSION['username'];
         //$postID=md5($post_title.$post_content.$usr.getdate());
         $post_Id = postModel::addPost($usr, $post_title, $post_content);
         if ($_FILES['imagepost']['name'] != NULL) {
             ///check error upload
             if ($_FILES['imagepost']['error'] > 0) {
                 if ($_FILES['imagepost']['error'] == UPLOAD_ERR_FORM_SIZE) {
                     $data['uploadfile'] = 'The file must not be bigger than 5mo.';
                 } else {
                     $data['uploadfile'] = 'The upload failed. Please try again, if this persists, contact the admin.';
                 }
                 //setup the error code
             }
             $valid_extensions = array('jpg', 'jpeg', 'gif', 'png');
             $extension_upload = strtolower(substr(strrchr($_FILES['imagepost']['name'], '.'), 1));
             if (!in_array($extension_upload, $valid_extensions)) {
                 $data['uploadfile'] = 'The extension isn\'t valid. The picture must be a jpg, jpeg, gig or png file.';
                 //setup the error code
             }
             /// end check error upload
             /// check error move
             $uploaddir = './images/posts/' . $post_Id . '/';
             //create the directory of theprofile pic
             if (!is_dir($uploaddir)) {
                 mkdir($uploaddir, 0777, true);
             }
             //give this image a random name (for multiple images)
             $temp = explode(".", $_FILES["imagepost"]["name"]);
             $newfilename = round(microtime(true)) . '.' . end($temp);
             $uploadfile = $uploaddir . $newfilename;
             if (file_exists($uploadfile)) {
                 $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.';
                 //setup the error code
             } elseif (!move_uploaded_file($_FILES['imagepost']['tmp_name'], $uploadfile)) {
                 //if error moving file
                 if (is_dir_empty($uploaddir)) {
                     rmdir($uploaddir);
                 }
                 //remove the directory  IF NOT EMPTY
                 $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.';
                 //setup the error code
             }
             if ($data['uploadfile'] != NULL) {
                 $post = postModel::getPost($post_Id);
                 $data['error'] = 'Post has been added but something went wrong with the picture. Please edit your post. ';
                 require_once $view['editpost'];
                 break;
             } else {
                 imageModel::addImagePost($post_Id, $usr, $newfilename);
             }
         }
         $post = postModel::getPost($post_Id);
         require_once $view['editpost'];
     } else {
         require_once $view['addpost'];
     }
 }