Example #1
0
/**
 * Callback function to validate data
 * @return bool must return true or other hooks don't get called
 */
function validateTranscript($editPage, $textBox1, $section, &$hookError)
{
    $ns = $editPage->mTitle->getNamespace();
    if ($ns == NS_TRANSCRIPT) {
        $transcript = new Transcript($editPage->mTitle->getText());
        $transcript->validate($textBox1, $section, $hookError);
    }
    return true;
}
Example #2
0
function show_transcript($per, $eid = -1, $sid = -1)
{
    $trans = new Transcript();
    $trans->setFromRequest();
    $dao = getTranscriptDAO();
    $dao->getTranscripts($trans, $eid, $sid);
    if ($trans->numResults > 0) {
        foreach ($trans->results as $t) {
            $t->person = $per;
        }
    }
    return show_transcript_details($trans);
}
Example #3
0
Settings::setProtected('db', $db);
// Initialize dispatcher
// --------------------------------------------------
$dispatch = new Dispatch();
$dispatch->register(array('DispatchController', 'getNextAvailableItem'));
Settings::setProtected('dispatch', $dispatch);
// Initialize event manager
// --------------------------------------------------
$eventManager = new EventManager();
Settings::setProtected('eventManager', $eventManager);
// Initialize transcript controller
// --------------------------------------------------
Transcript::setEventManager($eventManager);
Transcript::register('load', array('TranscriptController', 'load'));
Transcript::register('save', array('TranscriptController', 'save'));
Transcript::register('diff', array('TranscriptController', 'diff'));
// Initialize workflow controller
// --------------------------------------------------
Workflow::register('callback', array('WorkflowController', 'parse'));
// Initialize notifications controller
// --------------------------------------------------
$notifications = Settings::getProtected('notifications');
$notificationsList = array();
foreach ($notifications as $key => $value) {
    // Get an array of just the keys
    array_push($notificationsList, $key);
}
$notify = new NotificationManager();
$notify->setEventManager($eventManager);
$notify->registerNotifications($notificationsList, array('NotificationController', 'send'));
Settings::setProtected('notify', $notify);
Example #4
0
function setup_edit()
{
    $trans = new Transcript();
    $trans->setFromRequest();
    if (!isset($trans->transcript_id)) {
        if (isset($_REQUEST["person"]) && $trans->person->person_id > 0) {
            $trans->person->queryType = Q_IND;
            $dao = getPeopleDAO();
            $dao->getPersonDetails($trans->person);
            if ($trans->person->numResults == 0) {
                $trans->person = $trans->person->results[0];
            } else {
                $trans->person = new PersonDetail();
                $trans->person->setFromRequest();
            }
        } else {
            $trans->person = new PersonDetail();
            $trans->person->setFromRequest();
        }
        $trans->source = new Source();
        $trans->source->setFromRequest();
        if ($trans->source->source_id > 0) {
            $sdao = getSourceDAO();
            $sdao->getSources($trans->source);
            if ($trans->source->numResults > 0) {
                $trans->source = $trans->source->results[0];
            }
        }
        $ret = $trans;
    } else {
        $dao = getTranscriptDAO();
        $dao->getTranscripts($trans);
        if ($trans->numResults == 0) {
            if (isset($_REQUEST["event"])) {
                $dao = getEventDAO();
                $event = new Event();
                $event->setFromRequest();
                $dao->getEvents($event, Q_ALL);
                $trans->event = $event->results[0];
                $trans->person = $trans->event->person;
            }
            if ($trans->person->person_id > 0) {
                $trans->person->queryType = Q_IND;
                $dao = getPeopleDAO();
                $dao->getPersonDetails($trans->person);
                $trans->person = $trans->person->results[0];
            } else {
                $trans->person = new PersonDetail();
            }
            $trans->source = new Source();
            $trans->source->setFromRequest();
            if ($trans->source->source_id > 0) {
                $sdao = getSourceDAO();
                $sdao->getSources($trans->source);
                if ($trans->source->numResults > 0) {
                    $trans->source = $trans->source->results[0];
                }
            }
            $ret = $trans;
        } else {
            $ret = $trans->results[0];
        }
    }
    return $ret;
}
Example #5
0
//phpmyfamily - opensource genealogy webbuilder
//Copyright (C) 2002 - 2005  Simon E Booth (simon.booth@giric.com)
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// include the configuration parameters and function
include_once "modules/db/DAOFactory.php";
$trans = new Transcript();
$trans->setFromRequest();
$dao = getTranscriptDAO();
$dao->getTranscripts($trans);
foreach ($trans->results as $doc) {
    if (!$doc->person->isViewable()) {
        continue;
    }
    // see if we have mime capabilities
    if (function_exists("mime_content_type")) {
        $type = mime_content_type($doc->getFileName());
    } else {
        $type = "application/unknown";
    }
    // fire off a few headers
    header("Content-Location: " . $doc->getFileName());
Example #6
0
 public static function setEventManager($eventManager)
 {
     self::$eventManager = $eventManager;
 }
Example #7
0
$data = array('transcript_id' => 5, 'item_id' => 193, 'user_id' => 'username');
// Register save/load hooks
echo "Registering events...\n";
$eventManager = new EventManager();
$eventManager->register('load', 'transcript', 'onLoad');
$eventManager->register('save', 'transcript', 'onSave');
echo "Setting event manager...\n";
Transcript::setEventManager($eventManager);
// Register
echo "Registering transcript hooks...\n";
Transcript::register('load', 'myTranscriptLoadFunction');
Transcript::register('save', 'myTranscriptSaveFunction');
echo "Loading transcript...\n\n";
$transcript = new Transcript();
$transcript->load($data);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Changing text...\n";
$myText = "Hallelujah, it worked!";
$transcript->setText($myText);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Saving transcript...\n\n";
$transcript->save($data);
echo "Text for transcript: [" . $transcript->getText() . "]\n\n";
echo "Creating second transcript...\n";
$transcript2 = new Transcript();
$transcript2->setText("This is the second transcript.");
echo "Collating...\n";
$collated = Transcript::collate(array($transcript, $transcript2), "\n\n--**--\n\n");
echo "Collated version:\n";
echo $collated;
echo "\n";
 public static function transcript($params)
 {
     $format = Utils::getFormat($params['args'], 0, 2);
     $projectType = Utils::getProjectType($params['args']);
     $projectSlugIndex = $projectType == 'system' ? 0 : 2;
     $projectSlug = $params['args'][$projectSlugIndex];
     $itemIndex = $projectType == 'system' ? 1 : 3;
     $itemId = $params['args'][$itemIndex];
     $owner = $projectType == 'user' ? $params['args'][1] : '';
     $user = User::getAuthenticatedUser();
     switch ($params['method']) {
         // POST: Post transcript for item
         case 'POST':
             $proofType = Utils::POST('proofType');
             $proofUser = Utils::POST('proofUser');
             $transcriptText = Utils::POST('transcript');
             $transcriptStatus = Utils::POST('status');
             // draft, completed, reviewed
             $fields = Utils::POST('fields');
             $role = $proofType . "er";
             // Make sure they have access to the item
             if ($proofType == 'edit' || $proofUser != '') {
                 // For editing an item or a specific proof/review, user must be project admin or site admin
                 RoleController::forceClearance(array('project.admin', 'project.owner', 'system.admin'), $user, array('project' => $project));
             } else {
                 // User has to be a member of the project
                 if (!$user->isMember($projectSlug, $role, $owner)) {
                     Utils::redirectToDashboard("", $i18n->t("error.not_a_member"));
                     return;
                 }
             }
             // If we're looking at an existing proof/review, load it for that user
             // Otherwise load it for the existing user
             $username = $proofUser != '' ? $proofUser : $user->username;
             // Load the item
             $itemObj = new Item($itemId, $projectSlug, $username, $proofType);
             // Make sure item exists (if it fails, it'll return a boolean)
             if ($itemObj->item_id == -1) {
                 Utils::redirectToDashboard("", $i18n->t("error.nonexistent_item"));
                 return;
             }
             // Make sure the user has this item in their queue
             // TODO: Finish
             if ($proofType == 'edit') {
                 // Set the transcript and save the item
                 $itemObj->transcript = $transcriptText;
                 $itemObj->save();
             } else {
                 // Save transcript to database
                 $transcript = new Transcript();
                 $transcript->load(array('item' => $itemObj, 'type' => $proofType));
                 $transcript->setText($transcriptText);
                 $transcript->setFields($fields);
                 $transcript->save(array('item' => $itemObj, 'status' => $transcriptStatus, 'type' => $proofType));
                 // If we're looking at a user's proof or review, or if the transcript has already been
                 // completed/reviewed, then we don't want to update scoring and move the item through
                 // the workflow index
                 if ($proofUser == '' && $transcriptStatus != 'draft') {
                     $scoring = Settings::getProtected('scoring');
                     // Notifications
                     if ($transcriptStatus == 'reviewed') {
                         // Bump user's score up if they haven't already reviewed this item
                         $user->updateScoreForItem($itemObj->item_id, $itemObj->project_id, $scoring['review'], 'review');
                         // Notify project owner that review is complete
                     } else {
                         if ($transcriptStatus == 'completed') {
                             // Bump user's score up if they haven't already proofed this item
                             $user->updateScoreForItem($itemObj->item_id, $itemObj->project_id, $scoring['proof'], 'proof');
                         }
                     }
                     // Remove from user's queue
                     $userQueue = new Queue("user.{$proofType}:{$user->username}");
                     $userQueue->remove($itemObj);
                     $userQueue->save();
                     // Increase item's workflow index
                     $itemObj->workflow_index += 1;
                     // And save it
                     $itemObj->save();
                     // Load the project
                     $project = new Project($itemObj->project_slug);
                     // Get next workflow step
                     $workflow = new Workflow($project->workflow);
                     $workflow->setIndex($itemObj->workflow_index);
                     $workflowQueue = $workflow->getWorkflow();
                     if ($itemObj->workflow_index < count($workflowQueue)) {
                         // Process next step
                         $workflow->next($itemObj);
                     } else {
                         // The item is complete
                         $itemObj->setStatus("completed");
                     }
                 }
             }
             echo json_encode(array("statuscode" => "success"));
             break;
     }
 }
 public static function transcript($params)
 {
     $db = Settings::getProtected('db');
     // Parse parameters
     $format = Utils::getFormat($params['args'], 1, 3);
     $projectType = Utils::getProjectType($params['args']);
     $projectSlugIndex = $projectType == 'system' ? 0 : 2;
     $projectSlug = $params['args'][$projectSlugIndex];
     $project = new Project($projectSlug);
     $user = User::getAuthenticatedUser();
     // Make sure the user has access to download this
     RoleController::forceClearance(array('project.admin', 'project.owner', 'system.admin'), $user, array('project' => $project));
     switch ($params['method']) {
         // GET: download project transcript
         case 'GET':
             // Load project
             $project->getItems();
             $finalText = "";
             // Go through each item and get the relevant transcript
             foreach ($project->items as $item) {
                 $proofTranscripts = $db->loadItemTranscripts($item['project_id'], $item['id'], "proof");
                 $reviewTranscripts = $db->loadItemTranscripts($item['project_id'], $item['id'], "review");
                 // If there are reviewed transcripts, get the diff of those
                 $fieldTranscripts = array();
                 if (count($reviewTranscripts) > 0) {
                     if (count($reviewTranscripts) > 1) {
                         $text = Transcript::diff($reviewTranscripts);
                         foreach ($reviewTranscripts as $transcript) {
                             $fieldTranscripts[] = $transcript['fields'];
                         }
                     } else {
                         $text = $reviewTranscripts[0]['transcript'];
                         $fieldTranscripts[] = $reviewTranscripts[0]['fields'];
                     }
                 } else {
                     if (count($proofTranscripts) > 0) {
                         // If there are proofed transcripts, get the diff of those
                         if (count($proofTranscripts) > 1) {
                             $text = Transcript::diff($proofTranscripts);
                             foreach ($proofTranscripts as $transcript) {
                                 $fieldTranscripts[] = $transcript['fields'];
                             }
                         } else {
                             $text = $proofTranscripts[0]['transcript'];
                             $fieldTranscripts[] = $proofTranscripts[0]['fields'];
                         }
                     } else {
                         // Otherwise just get the item's original transcript
                         $text = $item['transcript'];
                     }
                 }
                 // Get the unique values for each of the item fields (if there are any)
                 $fields = array();
                 foreach ($fieldTranscripts as $transcript) {
                     // Convert from JSON string to object
                     $field = json_decode($transcript);
                     // Loop through the field transcript's properties
                     foreach ($field as $key => $value) {
                         // If the key isn't in the array, add it as an empty array
                         if (!array_key_exists($key, $fields)) {
                             $fields[$key] = array();
                         }
                         // If the value isn't in the array for that key, add it
                         if (!in_array($value, $fields[$key])) {
                             $fields[$key][] = $value;
                         }
                     }
                 }
                 // And serialize the fields to strings
                 $fieldStrings = array();
                 foreach ($fields as $field => $values) {
                     // If more than one, put in {a|b|c} format, otherwise just put the value
                     if (count($values) > 1) {
                         $str = "{" . join("|", $values) . "}";
                     } else {
                         $str = $values[0];
                     }
                     $fieldStrings[$field] = $str;
                 }
                 // Get the list of proofers/reviewers as comma-separated usernames
                 $stats = $db->getStatsForItem($item['id']);
                 $proofers = array();
                 $reviewers = array();
                 foreach ($stats['proofs'] as $stat) {
                     array_push($proofers, $stat['user']);
                 }
                 foreach ($stats['reviews'] as $stat) {
                     array_push($reviewers, $stat['user']);
                 }
                 $proofers = join(',', $proofers);
                 $reviewers = join(',', $reviewers);
                 // If there's a project template, use it, otherwise use default from config
                 $defaultTemplate = Settings::getProtected("download_template");
                 $template = $project->downloadTemplate != '' ? $project->downloadTemplate : $defaultTemplate;
                 // Apply the download template
                 $finalText .= TranscriptController::replaceVariables($template, array('transcript' => $text, 'project' => $project, 'item' => $item, 'proofers' => $proofers, 'reviewers' => $reviewers, 'fields' => $fieldStrings));
             }
             switch ($format) {
                 case 'json':
                     echo json_encode(array('transcript' => htmlentities($finalText)));
                     break;
                 case 'html':
                     $filename = "{$project->slug}.txt";
                     header("Content-Type: text/html");
                     header("Content-Disposition: attachment; filename={$filename}");
                     echo trim(str_replace('\\n', "\n", $finalText));
                     break;
             }
             break;
     }
 }
Example #10
0
<?php

include_once "modules/db/DAOFactory.php";
$peep = new PersonDetail();
$peep->queryType = Q_IND;
$pdao = getPeopleDAO();
$trans = new Transcript();
$trans->setFromRequest();
$dao = getTranscriptDAO();
if (isset($_REQUEST["func"]) && $_REQUEST["func"] == "delete") {
    $peep->setFromRequest();
    if ($peep->person_id > 0) {
        $pdao->getPersonDetails($peep);
        $peep = $peep->results[0];
        if (!$peep->isEditable()) {
            die(include "inc/forbidden.inc.php");
        }
    }
    $docFile = $trans->getFileName();
    if (@unlink($docFile) || !file_exists($docFile)) {
        $dao->deleteTranscript($trans);
    }
} else {
    $peep->setFromPost();
    if ($peep->person_id > 0) {
        $pdao->getPersonDetails($peep);
        $peep = $peep->results[0];
        if (!$peep->isEditable()) {
            die(include "inc/forbidden.inc.php");
        }
    }
 /**
  * Delete a transcript
  */
 public function actionDelete($roomId, $year, $month, $day)
 {
     // are we admin?
     if ($this->user->isAdmin()) {
         // form date
         $date = $year . '-' . $month . '-' . $day;
         try {
             // try to instantiate the transcript...
             $transcript = new Transcript($date, $roomId);
         } catch (TranscriptNotFoundException $e) {
             $this->renderAction('invalid');
         }
         // delete it
         $transcript->delete($date, $this->user->getShortName());
         // redirect back
         $this->redirectTo('/transcripts/');
     } else {
         $this->renderTemplate('Error404/error404');
     }
 }
 public static function getNextAvailableItem($params)
 {
     $username = $params['username'];
     $projectSlug = $params['projectSlug'];
     $type = $params['type'];
     $role = $type . "er";
     $success = false;
     $errorCode = '';
     $db = Settings::getProtected('db');
     $auth = Settings::getProtected('auth');
     // Make sure we're authenticated as the user we say we are
     $auth->forceAuthentication();
     $loggedInUsername = $auth->getUsername();
     if ($username != $loggedInUsername) {
         $code = "not-authenticated-as-correct-user";
     }
     // Load user
     $user = new User($username);
     // Does this user belong to the project?
     if (!$user->isMember($projectSlug, $role)) {
         $code = "not-a-member";
     }
     // Does this user already have an item from this project?
     if ($user->hasProjectItem($projectSlug)) {
         $code = "has-unfinished-item";
     }
     // Load the user's queue
     $userQueue = new Queue("user.{$type}:{$username}", false, array('include-removed' => true));
     $userQueueItems = $userQueue->getItems();
     // Load the project's queue
     $queue = new Queue("project.{$type}:{$projectSlug}");
     $queueItems = $queue->getItems();
     // Go through the project queue and get the first item the user hasn't yet done
     foreach ($queueItems as $item) {
         if (!in_array($item, $userQueueItems)) {
             $nextItem = $item;
             break;
         }
     }
     if (isset($nextItem) && $nextItem->item_id != -1) {
         // Concatenate proofed transcripts
         if ($type == 'review') {
             // Get proofed transcripts for the new item
             $transcripts = $db->loadItemTranscripts($nextItem->project_id, $nextItem->item_id, 'proof');
             // Only diff them if there's more than one
             if (count($transcripts) > 1) {
                 $transcriptText = Transcript::diff($transcripts);
             } else {
                 $transcriptText = $transcripts[0]['transcript'];
             }
             // Only get the fields for the first transcript
             $transcriptFields = $transcripts[0]['fields'];
             // Create transcript and add to the database
             $transcript = new Transcript();
             $transcript->setText($transcriptText);
             $transcript->setFields($transcriptFields);
             $transcript->save(array('item' => $nextItem, 'status' => 'draft', 'type' => 'review'));
         }
         // Reload the user's queue, this time ignoring items they've already done
         // Add it to the user's queue
         $userQueue = new Queue("user.{$type}:{$username}", false);
         $userQueue->add($nextItem);
         $userQueue->save();
         // Remove it from the project queue
         $queue->remove($nextItem);
         $queue->save();
         $success = true;
         $code = $nextItem->item_id;
     } else {
         $code = "no-item-available";
     }
     return array('status' => $success, 'code' => $code);
 }