require_login($course->id);
// to create notes the current user needs a capability
require_capability('moodle/notes:manage', $context);
if (!empty($users) && !empty($content) && confirm_sesskey()) {
    $note = new object();
    $note->courseid = $id;
    $note->format = FORMAT_PLAIN;
    $note->content = $content;
    $note->publishstate = $state;
    foreach ($users as $k => $v) {
        if (!($user = get_record('user', 'id', $v))) {
            continue;
        }
        $note->id = 0;
        $note->userid = $v;
        if (note_save($note)) {
            add_to_log($note->courseid, 'notes', 'add', 'index.php?course=' . $note->courseid . '&user='******'#note-' . $note->id, 'add note');
        }
    }
    redirect("{$CFG->wwwroot}/user/index.php?id={$id}");
}
/// Print headers
$straddnote = get_string('groupaddnewnote', 'notes');
$navlinks = array();
$navlinks[] = array('name' => $straddnote, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("{$course->shortname}: " . get_string('extendenrol'), $course->fullname, $navigation, "", "", true, " ", navmenu($course));
// this will contain all available the based On select options, but we'll disable some on them on a per user basis
print_heading($straddnote);
echo '<form method="post" action="groupaddnote.php" >';
echo '<div style="width:100%;text-align:center;">';
Example #2
0
 /**
  * Tests for event note_updated.
  */
 public function test_note_updated_event()
 {
     // Delete a note.
     $sink = $this->redirectEvents();
     $note = clone $this->eventnote;
     $note->publishstate = NOTES_STATE_DRAFT;
     note_save($note);
     $events = $sink->get_events();
     $event = array_pop($events);
     // Delete note event.
     $sink->close();
     // Validate event data.
     $this->assertInstanceOf('\\core\\event\\note_updated', $event);
     $this->assertEquals($note->id, $event->objectid);
     $this->assertEquals($note->usermodified, $event->userid);
     $this->assertEquals($note->userid, $event->relateduserid);
     $this->assertEquals('post', $event->objecttable);
     $this->assertEquals(NOTES_STATE_DRAFT, $event->other['publishstate']);
     // Test legacy data.
     $logurl = new \moodle_url('index.php', array('course' => $note->courseid, 'user' => $note->userid));
     $logurl->set_anchor('note-' . $note->id);
     $arr = array($note->courseid, 'notes', 'update', $logurl, 'update note');
     $this->assertEventLegacyLogData($arr, $event);
     $this->assertEventContextNotUsed($event);
 }
Example #3
0
        print_error('invalidformdata', '', $CFG->wwwroot . '/user/index.php?id=' . $id);
    }
    $note = new stdClass();
    $note->courseid = $id;
    $note->format = FORMAT_PLAIN;
    foreach ($users as $k => $v) {
        $user = $DB->get_record('user', array('id' => $v));
        $content = trim($contents[$k]);
        if (!$user || empty($content)) {
            continue;
        }
        $note->id = 0;
        $note->content = $content;
        $note->publishstate = $states[$k];
        $note->userid = $v;
        note_save($note);
    }
    redirect("{$CFG->wwwroot}/user/index.php?id={$id}");
}
// Print headers.
$straddnote = get_string('addnewnote', 'notes');
$PAGE->navbar->add($straddnote);
$PAGE->set_title("{$course->shortname}: " . get_string('extendenrol'));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
// This will contain all available the based On select options, but we'll disable some on them on a per user basis.
echo $OUTPUT->heading($straddnote);
echo '<form method="post" action="addnote.php">';
echo '<fieldset class="invisiblefieldset">';
echo '<input type="hidden" name="id" value="' . $course->id . '" />';
echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
Example #4
0
    /**
     * Create notes about some users
     * Note: code should be matching the /notes/edit.php checks
     * and the /user/addnote.php checks. (they are similar cheks)
     *
     * @param array $notes  An array of notes to create.
     * @return array (success infos and fail infos)
     * @since Moodle 2.2
     */
    public static function create_notes($notes = array()) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/notes/lib.php");

        $params = self::validate_parameters(self::create_notes_parameters(), array('notes' => $notes));

        //check if note system is enabled
        if (!$CFG->enablenotes) {
            throw new moodle_exception('notesdisabled', 'notes');
        }

        //retrieve all courses
        $courseids = array();
        foreach($params['notes'] as $note) {
            $courseids[] = $note['courseid'];
        }
        $courses = $DB->get_records_list("course", "id", $courseids);

        //retrieve all users of the notes
        $userids = array();
        foreach($params['notes'] as $note) {
            $userids[] = $note['userid'];
        }
        list($sqluserids, $sqlparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid_');
        $users = $DB->get_records_select("user", "id " . $sqluserids . " AND deleted = 0", $sqlparams);

        $resultnotes = array();
        foreach ($params['notes'] as $note) {

            $success = true;
            $resultnote = array(); //the infos about the success of the operation

            //check the course exists
            if (empty($courses[$note['courseid']])) {
                $success = false;
                $errormessage = get_string('invalidcourseid', 'notes', $note['courseid']);
            } else {
                // Ensure the current user is allowed to run this function
                $context = get_context_instance(CONTEXT_COURSE, $note['courseid']);
                self::validate_context($context);
                require_capability('moodle/notes:manage', $context);
            }

            //check the user exists
            if (empty($users[$note['userid']])) {
                $success = false;
                $errormessage = get_string('invaliduserid', 'notes', $note['userid']);
            }

            //build the resultnote
            if (isset($note['clientnoteid'])) {
                $resultnote['clientnoteid'] = $note['clientnoteid'];
            }

            if ($success) {
                //now we can create the note
                $dbnote = new stdClass;
                $dbnote->courseid = $note['courseid'];
                $dbnote->userid = $note['userid'];
                //clean param text and set format accordingly
                switch (strtolower($note['format'])) {
                    case 'html':
                        $dbnote->content = clean_param($note['text'], PARAM_CLEANHTML);
                        $dbnote->format = FORMAT_HTML;
                        break;
                    case 'text':
                    default:
                        $dbnote->content = clean_param($note['text'], PARAM_TEXT);
                        $dbnote->format = FORMAT_PLAIN;
                        break;
                }

                //get the state ('personal', 'course', 'site')
                switch ($note['publishstate']) {
                    case 'personal':
                        $dbnote->publishstate = NOTES_STATE_DRAFT;
                        break;
                    case 'course':
                        $dbnote->publishstate = NOTES_STATE_PUBLIC;
                        break;
                    case 'site':
                        $dbnote->publishstate = NOTES_STATE_SITE;
                        $dbnote->courseid = SITEID;
                        break;
                    default:
                        break;
                }

                //TODO MDL-31119 performance improvement - if possible create a bulk functions for saving multiple notes at once
                if (note_save($dbnote)) { //note_save attribut an id in case of success
                    add_to_log($dbnote->courseid, 'notes', 'add',
                            'index.php?course='.$dbnote->courseid.'&amp;user='******'#note-' . $dbnote->id , 'add note');
                    $success = $dbnote->id;
                }

                $resultnote['noteid'] = $success;
            } else {
                $resultnote['noteid'] = -1;
                $resultnote['errormessage'] = $errormessage;
            }

            $resultnotes[] = $resultnote;
        }

        return $resultnotes;
    }
            $OUTPUT = update($_POST);
            break;
        case "display":
            $OUTPUT = financialStatements::trialbal($_POST);
            $ql = true;
            break;
        case ct("Print"):
        case ct("Save"):
        case ct("Export to Spreadsheet"):
            $OUTPUT = print_report();
            break;
        case "note_view":
            $OUTPUT = note_view($_POST);
            break;
        case "note_save":
            $OUTPUT = note_save($_POST);
            break;
    }
} else {
    $OUTPUT = customize($_POST);
    //$OUTPUT = financialStatements::trialbal($_GET);
    $ql = true;
}
require "../template.php";
function customize($_POST)
{
    extract($_POST);
    $fields["naccount"] = "";
    $fields["last_year"] = "checked";
    $fields["budget"] = "checked";
    $fields["month_from"] = (int) date("m");
Example #6
0
 /**
  * Update notes about users.
  *
  * @param array $notes An array of ids for the notes to update.
  * @return array fail infos.
  * @since Moodle 2.2
  */
 public static function update_notes($notes = array())
 {
     global $CFG, $DB;
     $params = self::validate_parameters(self::update_notes_parameters(), array('notes' => $notes));
     // Check if note system is enabled.
     if (!$CFG->enablenotes) {
         throw new moodle_exception('notesdisabled', 'notes');
     }
     $warnings = array();
     foreach ($params['notes'] as $note) {
         $notedetails = note_load($note['id']);
         if (isset($notedetails->id)) {
             // Ensure the current user is allowed to run this function.
             $context = context_course::instance($notedetails->courseid);
             self::validate_context($context);
             require_capability('moodle/notes:manage', $context);
             $dbnote = new stdClass();
             $dbnote->id = $note['id'];
             $dbnote->content = $note['text'];
             $dbnote->format = external_validate_format($note['format']);
             // Get the state ('personal', 'course', 'site').
             switch ($note['publishstate']) {
                 case 'personal':
                     $dbnote->publishstate = NOTES_STATE_DRAFT;
                     break;
                 case 'course':
                     $dbnote->publishstate = NOTES_STATE_PUBLIC;
                     break;
                 case 'site':
                     $dbnote->publishstate = NOTES_STATE_SITE;
                     $dbnote->courseid = SITEID;
                     break;
                 default:
                     $warnings[] = array('item' => 'note', 'itemid' => $note["id"], 'warningcode' => 'badparam', 'message' => 'Provided publishstate incorrect');
                     break;
             }
             if (!note_save($dbnote)) {
                 $warnings[] = array('item' => 'note', 'itemid' => $note["id"], 'warningcode' => 'savedfailed', 'message' => 'Note could not be modified');
             }
         } else {
             $warnings[] = array('item' => 'note', 'itemid' => $note["id"], 'warningcode' => 'badid', 'message' => 'Note does not exist');
         }
     }
     return $warnings;
 }
 /**
  * Create notes about some users
  * Note: code should be matching the /notes/edit.php checks
  * and the /user/addnote.php checks. (they are similar cheks)
  *
  * @param array $notes  An array of notes to create.
  * @return array (success infos and fail infos)
  * @since Moodle 2.2
  */
 public static function create_notes($notes = array())
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . "/notes/lib.php";
     $params = self::validate_parameters(self::create_notes_parameters(), array('notes' => $notes));
     //check if note system is enabled
     if (!$CFG->enablenotes) {
         throw new moodle_exception('notesdisabled', 'notes');
     }
     //retrieve all courses
     $courseids = array();
     foreach ($params['notes'] as $note) {
         $courseids[] = $note['courseid'];
     }
     $courses = $DB->get_records_list("course", "id", $courseids);
     //retrieve all users of the notes
     $userids = array();
     foreach ($params['notes'] as $note) {
         $userids[] = $note['userid'];
     }
     list($sqluserids, $sqlparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid_');
     $users = $DB->get_records_select("user", "id " . $sqluserids . " AND deleted = 0", $sqlparams);
     $resultnotes = array();
     foreach ($params['notes'] as $note) {
         $success = true;
         $resultnote = array();
         //the infos about the success of the operation
         //check the course exists
         if (empty($courses[$note['courseid']])) {
             $success = false;
             $errormessage = get_string('invalidcourseid', 'error');
         } else {
             // Ensure the current user is allowed to run this function
             $context = get_context_instance(CONTEXT_COURSE, $note['courseid']);
             self::validate_context($context);
             require_capability('moodle/notes:manage', $context);
         }
         //check the user exists
         if (empty($users[$note['userid']])) {
             $success = false;
             $errormessage = get_string('invaliduserid', 'notes', $note['userid']);
         }
         //build the resultnote
         if (isset($note['clientnoteid'])) {
             $resultnote['clientnoteid'] = $note['clientnoteid'];
         }
         if ($success) {
             //now we can create the note
             $dbnote = new stdClass();
             $dbnote->courseid = $note['courseid'];
             $dbnote->userid = $note['userid'];
             // Need to support 'html' and 'text' format values for backward compatibility.
             switch (strtolower($note['format'])) {
                 case 'html':
                     $textformat = FORMAT_HTML;
                     break;
                 case 'text':
                     $textformat = FORMAT_PLAIN;
                 default:
                     $textformat = external_validate_format($note['format']);
                     break;
             }
             $dbnote->content = $note['text'];
             $dbnote->format = $textformat;
             //get the state ('personal', 'course', 'site')
             switch ($note['publishstate']) {
                 case 'personal':
                     $dbnote->publishstate = NOTES_STATE_DRAFT;
                     break;
                 case 'course':
                     $dbnote->publishstate = NOTES_STATE_PUBLIC;
                     break;
                 case 'site':
                     $dbnote->publishstate = NOTES_STATE_SITE;
                     $dbnote->courseid = SITEID;
                     break;
                 default:
                     break;
             }
             //TODO MDL-31119 performance improvement - if possible create a bulk functions for saving multiple notes at once
             if (note_save($dbnote)) {
                 //note_save attribut an id in case of success
                 add_to_log($dbnote->courseid, 'notes', 'add', 'index.php?course=' . $dbnote->courseid . '&amp;user='******'#note-' . $dbnote->id, 'add note');
                 $success = $dbnote->id;
             }
             $resultnote['noteid'] = $success;
         } else {
             // WARNINGS: for backward compatibility we return this errormessage.
             //          We should have thrown exceptions as these errors prevent results to be returned.
             // See http://docs.moodle.org/dev/Errors_handling_in_web_services#When_to_send_a_warning_on_the_server_side .
             $resultnote['noteid'] = -1;
             $resultnote['errormessage'] = $errormessage;
         }
         $resultnotes[] = $resultnote;
     }
     return $resultnotes;
 }
Example #8
0
 /**
  * Create a new note.
  *
  * @param array|stdClass $record
  * @throws coding_exception
  * @return stdClass activity record with extra cmid field
  */
 public function create_instance($record = null)
 {
     global $CFG, $USER;
     require_once "{$CFG->dirroot}/notes/lib.php";
     $this->instancecount++;
     $i = $this->instancecount;
     $record = (object) (array) $record;
     if (empty($record->courseid)) {
         throw new coding_exception('Module generator requires $record->courseid.');
     }
     if (empty($record->userid)) {
         throw new coding_exception('Module generator requires $record->userid.');
     }
     if (!isset($record->module)) {
         $record->module = 'notes';
     }
     if (!isset($record->groupid)) {
         $record->groupid = 0;
     }
     if (!isset($record->moduleid)) {
         $record->moduleid = 0;
     }
     if (!isset($record->coursemoduleid)) {
         $record->coursemoduleid = 0;
     }
     if (!isset($record->subject)) {
         $record->subject = '';
     }
     if (!isset($record->summary)) {
         $record->summary = null;
     }
     if (!isset($record->content)) {
         $record->content = "This is test generated note - {$i} .";
     }
     if (!isset($record->uniquehash)) {
         $record->uniquehash = '';
     }
     if (!isset($record->rating)) {
         $record->rating = 0;
     }
     if (!isset($record->format)) {
         $record->format = FORMAT_PLAIN;
     }
     if (!isset($record->summaryformat)) {
         $record->summaryformat = FORMAT_MOODLE;
     }
     if (!isset($record->attachment)) {
         $record->attachment = null;
     }
     if (!isset($record->publishstate)) {
         $record->publishstate = NOTES_STATE_SITE;
     }
     if (!isset($record->lastmodified)) {
         $record->lastmodified = time();
     }
     if (!isset($record->created)) {
         $record->created = time();
     }
     if (!isset($record->usermodified)) {
         $record->usermodified = $USER->id;
     }
     note_save($record);
     return $record;
 }