예제 #1
0
 static function createUser($data, $error = null)
 {
     $data["password"] = Filter::encodePassword($data["passowrd"]);
     $data = Filter::filterArray($data);
     $user = new User($data);
     $u = $user->save();
     //echo "<p>" . $user . "</p>"; //DEBUG
     if ($u !== false) {
         //invia una mail per permettere all'utente di convalidare la sua casella.
         $code = self::generateValidationCode($u);
         mail($u->getMail(), "Iscrizione a IoEsisto", self::generateValidationMailMessage($code));
         //genera una collection di preferiti
         require_once 'post/collection/CollectionManager.php';
         $data = array("title" => "Preferiti", "author" => $u->getID(), "categories" => "favourites", "visible" => false);
         CollectionManager::createCollection($data);
         //genera tre directory email: mailbox, cestino e spam
         require_once "mail/MailManager.php";
         MailManager::createDirectory(MAILBOX, $u->getID());
         MailManager::createDirectory(TRASH, $u->getID());
         MailManager::createDirectory(SPAM, $u->getID());
     }
     return $user;
 }
예제 #2
0
 function testDeleteDirectory()
 {
     $data = $this->mail_data;
     $mail = MailManager::createMail($data);
     $dir = MailManager::createDirectory($this->dir_name, $this->author_id);
     $mailbox = MailManager::loadDirectoryFromName(MAILBOX, $this->author_id);
     $oldmailboxcount = count($dir->getMails());
     //echo "<p>" . $mail . "<br />" . $dir . "</p>"; //DEBUG
     if ($dir == null || $dir === false) {
         return "<br />Directory test NOT PASSED: not created";
     }
     $dir2 = MailManager::deleteDirectory($dir);
     $dir = MailManager::loadDirectory($dir2->getID());
     $mailbox2 = MailManager::loadDirectoryFromName(MAILBOX, $this->author_id);
     //echo "<p>" . $mailbox . "<br />" . $mailbox2 . "</p>"; //DEBUG
     if ($dir !== false) {
         return "<br />Directory test NOT PASSED: not deleted";
     }
     if (count($mailbox2->getMails()) == $oldmailboxcount) {
         return "<br />Directory test NOT PASSED: not moved to Mailbox";
     }
     return "<br />Directory deleting test passed";
 }
예제 #3
0
    static function showEditDirectoryForm($error = null, $directory = null)
    {
        $user = Session::getUser();
        if (count($_POST) == 0) {
            ?>
			<form name="editdirectory" action="" method="post">
				<fieldset>
					<legend>New Directory</legend>	
					Name*: <input type="text" name="name" /> 
					<input type="submit" name="create" value="create" /> <?php 
            if (isset($error["name"])) {
                echo $error["name"];
            }
            ?>
				
				</fieldset>
				<fieldset>
					<legend>Delete Directory</legend>
					Check the directory that you wish delete<br />
					<script type="text/javascript">
						var nomiOriginali;						

						function clickRename(event)
						{
							var id =  parseInt(event.target.id);							
							document.getElementById( id + "name" ).removeAttribute('readOnly');
							document.getElementById( id + "confirm").disabled = false;
							document.getElementById( id + "cancel").disabled = false;
							event.target.disabled = true;
						}

						function clickCancel(event)
						{
							var id =  parseInt(event.target.id);
							document.getElementById( id + "name" ).setAttribute('readOnly','readOnly');
							document.getElementById( id + "confirm" ).disabled = true;
							document.getElementById( id + "rename" ).disabled = false;
							event.target.disabled = true;
						}
					</script>	
					<?php 
            if ($user != false) {
                $directoryarray = MailManager::loadUsersDirectories($user->getID());
                if ($directoryarray != false) {
                    foreach ($directoryarray as $directory) {
                        echo "<input type=\"checkbox\" name=\"exdirar[]\" value=\"" . $directory->getID() . "\" />\n\t\t\t\t\t\t\t\t\t\t<input type=\"text\" readonly=\"readonly\" id=\"" . $directory->getID() . "name\" name=\"" . $directory->getName() . "\" value=\"" . $directory->getName() . "\" />\n\t\t\t\t\t\t\t\t\t\t<button type=\"button\" id=\"" . $directory->getID() . "rename\" onclick=\"clickRename(event);\" >rename</button>\n\t\t\t\t\t\t\t\t\t\t<input type=\"submit\" id=\"" . $directory->getID() . "confirm\" name=\"" . $directory->getName() . "\" value=\"confirm\" disabled=\"disabled\" />\n\t\t\t\t\t\t\t\t\t\t<button id=\"" . $directory->getID() . "cancel\" disabled=\"disabled\"  onclick=\"clickCancel(event);\" />cancel</button><br />";
                    }
                }
            }
            ?>
					<input type="submit" name="delete" value="delete" />				
				</fieldset>
			</form>
			<?php 
        } else {
            $error = array();
            if (isset($_POST["create"]) && $_POST["create"] == "create") {
                if (isset($_POST["name"]) && $_POST["name"] !== "") {
                    MailManager::createDirectory($_POST["name"], $user->getID());
                    return true;
                } else {
                    $error["name"] = "it's obbligatory";
                    $_POST = array();
                    self::showEditDirectoryForm($error, $directory);
                }
            }
            if (isset($_POST["delete"]) && $_POST["delete"] == "delete") {
                if ($user != false) {
                    //loadDirectory(,$user);
                    MailManager::deleteDirectory();
                }
            }
        }
    }