Ejemplo n.º 1
0
 public function indexAction()
 {
     //从URL中获取请求的category_id
     $request = $this->getRequest();
     $category_id = $request->getParam('category_id');
     $user_id = $this->_user->user_id;
     $this->_db_user->load($user_id);
     $notes = new Database_Notes($this->_db);
     $category_name = $notes->categoryIdToName($category_id);
     try {
         if (!$notes->checkThisUserHasThisCategory($user_id, $category_id)) {
             throw new RuntimeException('This category is not belong to you.', '0x0002');
         }
     } catch (RuntimeException $e) {
         Lds_Helper_Log::writeLog($e);
         Lds_Helper_Redirect::goTo('/', 'You Have not right to access this page', 3);
     }
     $param = array('user_id' => $this->_db_user->getId(), 'category_id' => $category_id);
     $command = new Command_GetNoteByCategoryId($notes, $param);
     $this->_db_user->setCommand($command);
     $notes = $this->_db_user->executeCommand();
     $this->view->notes = $notes;
     $this->view->category_name = $category_name;
     $this->view->category_id = $category_id;
     var_dump($notes);
 }
Ejemplo n.º 2
0
 public function indexAction()
 {
     $user_id = $this->_user->user_id;
     $this->_db_user->load($user_id);
     // create a new notes
     $notes = new Database_Notes($this->_db);
     $categorys = $notes->getMyCategorysByUserId($user_id);
     $this->view->categorys = $categorys;
     var_dump($categorys);
 }
Ejemplo n.º 3
0
 public function indexAction()
 {
     //$auth = Zend_Auth::getInstance();
     //$user = $auth->getIdentity();
     //$this->view->user = $user;
     $user_id = $this->_user->user_id;
     $this->_db_user->load($user_id);
     // get my  categories
     $notes = new Database_Notes($this->_db);
     $categorys = $notes->getMyCategorysByUserId($user_id);
     $this->view->categorys = $categorys;
     var_dump($categorys);
 }
Ejemplo n.º 4
0
 protected function tearDown()
 {
     $database_notes = Database_Notes::getInstance();
     foreach ($this->note_identifiers as $identifier) {
         $database_notes->delete($identifier);
     }
 }
Ejemplo n.º 5
0
 public static function checksum($identifiers)
 {
     $database_notes = Database_Notes::getInstance();
     $checksums = array();
     foreach ($identifiers as $identifier) {
         $checksums[] = $database_notes->getChecksum($identifier);
     }
     $checksum = implode("", $checksums);
     $checksum = md5($checksum);
     return $checksum;
 }
Ejemplo n.º 6
0
 /** 
  * 执行命名前检查相关的权限
  * 
  * @param $user_id
  * @param $compare
  * 
  * @return 
  */
 public function checkPermission($user_id, $compareType, $compare)
 {
     $db = Zend_Registry::get('db');
     switch ($compareType) {
         case 'note_id':
             $note = new Database_Notes($db);
             $note->load($compare);
             return $user_id == $note->user_id ? true : false;
             break;
         case 'tag_name':
             break;
         case 'category_id':
             $userLinkCategory = new Database_UserLinkCategory($db);
             return $userLinkCategory->thisUserHasThisCategory($user_id, $compare);
             break;
         case 'category_name':
             break;
         default:
             return false;
     }
 }
Ejemplo n.º 7
0
 public function consultationNote($id)
 {
     $database_notes = Database_Notes::getInstance();
     $database_logs = Database_Logs::getInstance();
     $passage = $database_notes->getPassages($id);
     $passageText = Filter_Books::passagesDisplayInline($passage);
     $summary = $database_notes->getSummary($id);
     $contents = $database_notes->getContents($id);
     $contents = Filter_Html::html2text($contents);
     $session_logic = Session_Logic::getInstance();
     $username = $session_logic->currentUser();
     $database_logs->log("{$username} deleted / marked for deletion consultation note {$passageText} | {$summary} | {$contents}");
 }
Ejemplo n.º 8
0
 public function createUser($username, $password)
 {
     $safeCode = self::makeToken($username);
     $this->username = $username;
     $this->password = self::makePassword($password, $safeCode);
     $this->safecode = $safeCode;
     $this->save();
     $user_id = $this->getId();
     //为新用户分配其他数据,如附赠系统分类
     //$query = 'CALL register(?)';
     //$query = $this->_db->quoteInto($query,$user_id);
     //$this->_db->query($query);
     //附赠系统分类
     //TODO : 应该order表中读取分类时依赖于category_id
     //所以目前category表无法作为字典表,用户不能复用相同id的category
     //今后可以改进,避免每注册一个用户就无谓的为category表添加相同的系统分类
     $userDB = new Database_Notes($this->_db);
     $system_categories = array('Inbox', 'Today', 'Next', 'Maybe', 'Projects', 'Areas');
     foreach ($system_categories as $category_name) {
         $userDB->addCategory($category_name, $user_id);
     }
     return $user_id;
 }
Ejemplo n.º 9
0
 /**
  * This imports one note from Bibledit-Gtk.
  * The note is available in $filename.
  * It returns the identifier of the note if imported successfully.
  * Else it returns NULL.
  */
 public static function importFromBibleditGtkFile($filename)
 {
     $note_identifier = NULL;
     if (file_exists($filename)) {
         // The note is in the format as used by Bibledit-Gtk.
         // The filename represents the note ID in Bibledit-Gtk.
         // This ID is not relevant for import.
         // Read the note.
         $note = file($filename);
         // line 0: date created.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 1: user who created it.
         // This information is not used here. The same information will be in the logbook entries, see later.
         // line 2: note references.
         // Sample: Exod.29.23
         // Sample: Lev.26.16 Deut.28.22
         // It uses OSIS for book encoding.
         $passages = array();
         foreach (explode(" ", trim($note[2])) as $bibledit_gtk_reference) {
             $passages[] = Filter_Books::explodePassage($bibledit_gtk_reference);
         }
         // line 3: note category.
         $category = trim($note[3]);
         // line 4: Bible.
         $bible = trim($note[4]);
         // line 5: date modified.
         // This information is list since the note will be modified upon import.
         // line 6 and up: note text, "Logbook:", and logbook entries.
         // Summary will be taken from the first line.
         $summary = trim($note[6]);
         $contents = "";
         for ($i = 6; $i < count($note); $i++) {
             $contents .= $note[$i] . "\n";
         }
         // Store note.
         // (In client mode, upon sync to the server, these notes will be erased: Import them on the server).
         $database_notes = Database_Notes::getInstance();
         $note_identifier = $database_notes->storeNewNote($bible, 0, 0, 0, $summary, $contents, true);
         $database_notes->setPassages($note_identifier, $passages, true);
         $database_notes->setStatus($note_identifier, $category, true);
     }
     return $note_identifier;
 }
Ejemplo n.º 10
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Database_Notes();
     }
     // Enter the standard statuses in the list of translatable strings.
     if (false) {
         Locale_Translate::_("New");
         Locale_Translate::_("Pending");
         Locale_Translate::_("In progress");
         Locale_Translate::_("Done");
         Locale_Translate::_("Reopened");
     }
     // Enter the standard severities in the list of translatable strings.
     if (false) {
         Locale_Translate::_("Wish");
         Locale_Translate::_("Minor");
         Locale_Translate::_("Normal");
         Locale_Translate::_("Important");
         Locale_Translate::_("Major");
         Locale_Translate::_("Critical");
     }
     return self::$instance;
 }
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
require_once "../bootstrap/bootstrap.php";
Filter_Cli::assert();
$object = Filter_Cli::argument(@$argv, 1);
$database_config_bible = Database_Config_Bible::getInstance();
$database_notes = Database_Notes::getInstance();
$url = $database_config_bible->getRemoteRepositoryUrl($object);
$directory = Filter_Git::git_directory($object);
$consultationsfolder = $database_notes->mainFolder();
// Our data goes into the local repository.
echo Locale_Translate::_("Step 1/2:") . " ";
echo Locale_Translate::_("Exporting the local Bible data to the local repository") . "\n";
Filter_Git::syncBible2Git($object, $directory, true);
// Directory for use by the shell.
$shelldirectory = escapeshellarg($directory);
// Add and commit the data.
$command = "cd {$shelldirectory}; git add --all .";
echo "{$command}\n";
exec($command, $output, $exit_code);
echo "Exit code {$exit_code}\n";
if ($exit_code != 0) {
Ejemplo n.º 12
0
 /**
  * handleEmailNew - handles an email received from $from with subject $subject and body $body.
  * Returns true if the mail was processed, else false.
  * The email is considered to have been processed if it created a new Consultation Note.
  */
 public function handleEmailNew($from, $subject, $body)
 {
     // Store the original subject.
     $originalSubject = $subject;
     // Check that the subject indicates that a new consultation note is to be created.
     $pos = strpos(strtolower($subject), "new note");
     if ($pos === false) {
         return false;
     }
     // There is a new note. Remove that bit from the $subject.
     $subject = substr($subject, 0, $pos) . substr($subject, $pos + 8);
     // Clean the subject line.
     $subject = trim($subject);
     $subject = str_replace(".", " ", $subject);
     $subject = str_replace(":", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     $subject = str_replace("  ", " ", $subject);
     // Check that the $from address of the email belongs to an existing user.
     $from = Filter_Email::extractEmail($from);
     $database_users = Database_Users::getInstance();
     if (!$database_users->emailExists($from)) {
         return false;
     }
     $username = $database_users->getEmailToUser($from);
     // Extract book, chapter, verse, and note summary from the $subject
     $book = NULL;
     $chapter = NULL;
     $verse = NULL;
     $summary = NULL;
     $subject = explode(" ", $subject);
     if (count($subject) > 0) {
         $book = Filter_Books::interpretBook($subject[0]);
     }
     if (count($subject) > 1) {
         $chapter = Filter_Numeric::integer_in_string($subject[1]);
     }
     if (count($subject) > 2) {
         $verse = Filter_Numeric::integer_in_string($subject[2]);
     }
     unset($subject[0]);
     unset($subject[1]);
     unset($subject[2]);
     $summary = implode(" ", $subject);
     unset($subject);
     // Check book, chapter, verse, and summary. Give feedback if there's anything wrong.
     $noteCheck = "";
     if (!(is_numeric($book) && $book > 0)) {
         $noteCheck .= Locale_Translate::_("Unknown book");
     }
     if (!is_numeric($chapter)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown chapter");
     }
     if (!is_numeric($verse)) {
         $noteCheck .= " " . Locale_Translate::_("Unknown verse");
     }
     if ($summary == NULL || $summary == "") {
         $noteCheck .= " " . Locale_Translate::_("Unknown summary");
     }
     // Mail user if the note could not be posted.
     $database_mail = Database_Mail::getInstance();
     if ($noteCheck != "") {
         $subject = Locale_Translate::_("Your new note could not be posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $noteCheck);
         return false;
     }
     // Clean the email's body.
     $body = Filter_Email::extractBody($body);
     // Post the note.
     $session_logic = Session_Logic::getInstance();
     $sessionuser = $session_logic->currentUser();
     $session_logic->setUsername($username);
     $database_notes = Database_Notes::getInstance();
     $identifier = $database_notes->storeNewNote("", $book, $chapter, $verse, $summary, $body, false);
     $this->handlerNewNote($identifier);
     $session_logic->setUsername($sessionuser);
     // Mail confirmation to the $username.
     $database_config_user = Database_Config_User::getInstance();
     if ($database_config_user->getUserNotifyMeOfMyPosts($username)) {
         $subject = Locale_Translate::_("Your new note was posted");
         $database_mail->send($username, $subject . ": " . $originalSubject, $body);
     }
     // Log operation.
     $database_logs = Database_Logs::getInstance();
     $database_logs->log("New note posted" . ":" . " " . $body);
     // Job done.
     return true;
 }
Ejemplo n.º 13
0
 public function testAvailability()
 {
     $database_notes = Database_Notes::getInstance();
     $this->assertTrue($database_notes->available());
     $database_notes->set_availability(false);
     $this->assertFalse($database_notes->available());
     $database_notes->set_availability(true);
     $this->assertTrue($database_notes->available());
 }
Ejemplo n.º 14
0
 /** 
  * 测试 delNote
  * 
  * @return 
  */
 public function testDelNote()
 {
     $db = Zend_Registry::get('db');
     $note = new Database_Notes($db);
     $post = array('user_id' => 1, 'content' => 'liudingsan', 'tags' => 'tag_when_addNote', 'categorys' => array('cate1', 'cate2'));
     //创建一个新note,以post数组为参数
     $new_note = $note->createNote($post);
     $new_note_id = $new_note['note_id'];
     $note->load($new_note_id);
     $tag = $note->tagIsExistInThisNote('tag_when_addNote');
     $this->assertTrue($tag);
     $this->assertTrue($note->categoryIsExistInThisNote('cate1'));
     $this->assertTrue($note->categoryIsExistInThisNote('cate2'));
     $note_all = $note->getOneNote();
     //	var_dump($note_all);
     //新建一个tag,用于判断delNote是否能删除其归属的tag
     $tag_name = 'new_tag_12_18';
     $note->addTag($tag_name);
     //重载,检查addTag正常
     $note->load($new_note_id);
     $tag_is_added = $note->tagIsExistInThisNote($tag_name);
     $this->assertTrue($tag_is_added);
     //测试delNote
     $result = $note->delNote();
     $this->assertTrue($result);
     //重载,测试tag是否删除
     $note_is_gone = $note->load($new_note_id);
     $this->assertFalse($note_is_gone);
     //$tag_is_gone = $note->tagIsExistInThisNote($tag_name);
     //$this->assertFalse($tag_is_gone);
 }
Ejemplo n.º 15
0
function die_if_databases_unhealthy_or_busy()
{
    $database_notes = Database_Notes::getInstance();
    $available = true;
    if (!$database_notes->healthy()) {
        $available = false;
    }
    if (!$database_notes->checksums_healthy()) {
        $available = false;
    }
    if (!$database_notes->available()) {
        $available = false;
    }
    if (!$available) {
        $database_logs = Database_Logs::getInstance();
        $database_logs->log("Notes databases are unhealthy or unavailable", Filter_Roles::TRANSLATOR_LEVEL);
        die;
    }
}