Skip to content

Commit

Permalink
Fix inserts/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Aug 12, 2015
1 parent a8b5bf1 commit a5b4f26
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 20 deletions.
7 changes: 6 additions & 1 deletion main/attendance/attendance_edit.php
Expand Up @@ -66,7 +66,12 @@
$default['attendance_qualify_title'] = $attendance_qualify_title;
$default['attendance_weight'] = $attendance_weight;

$link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 7, $attendance_id, api_get_session_id());
$link_info = GradebookUtils::is_resource_in_course_gradebook(
api_get_course_id(),
7,
$attendance_id,
api_get_session_id()
);
$default['category_id'] = $link_info['category_id'];
$form->setDefaults($default);
$form->display();
49 changes: 42 additions & 7 deletions main/course_progress/thematic_advance.php
Expand Up @@ -19,7 +19,12 @@
}

// display form
$form = new FormValidator('thematic_advance','POST','index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq());
$form = new FormValidator(
'thematic_advance',
'POST',
'index.php?action=thematic_advance_list&thematic_id='.$thematic_id.'&'.api_get_cidreq(
)
);
$form->addElement('header', $header_form);
//$form->addElement('hidden', 'thematic_advance_token',$token);
$form->addElement('hidden', 'action', $action);
Expand Down Expand Up @@ -68,8 +73,27 @@

$form->addElement('html', '</div>');

$form->addText('duration_in_hours', get_lang('DurationInHours'), false, array('size'=>'3','id'=>'duration_in_hours_element', 'autofocus' => 'autofocus'));
$form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarStartExpanded'=>'false', 'ToolbarSet' => 'TrainingDescription', 'Height' => '150'));
$form->addText(
'duration_in_hours',
get_lang('DurationInHours'),
false,
array(
'size' => '3',
'id' => 'duration_in_hours_element',
'autofocus' => 'autofocus',
)
);
$form->addHtmlEditor(
'content',
get_lang('Content'),
false,
false,
array(
'ToolbarStartExpanded' => 'false',
'ToolbarSet' => 'TrainingDescription',
'Height' => '150',
)
);

if ($action == 'thematic_advance_add') {
$form->addButtonSave(get_lang('Save'));
Expand Down Expand Up @@ -131,20 +155,31 @@
} else if ($action == 'thematic_advance_list') {
// thematic advance list
echo '<div class="actions">';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.Display::return_icon('back.png', get_lang("BackTo"),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_details">'.
Display::return_icon('back.png', get_lang("BackTo"),'',ICON_SIZE_MEDIUM).'</a>';
if (api_is_allowed_to_edit(false, true)) {
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.Display::return_icon('add.png', get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&amp;action=thematic_advance_add&amp;thematic_id='.$thematic_id.'"> '.
Display::return_icon('add.png', get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a>';
}
echo '</div>';
$table = new SortableTable('thematic_advance_list', array('Thematic', 'get_number_of_thematic_advances'), array('Thematic', 'get_thematic_advance_data'));
$table = new SortableTable(
'thematic_advance_list',
array('Thematic', 'get_number_of_thematic_advances'),
array('Thematic', 'get_thematic_advance_data')
);
//$table->set_additional_parameters($parameters);
$table->set_header(0, '', false, array('style'=>'width:20px;'));
$table->set_header(1, get_lang('StartDate'), false);
$table->set_header(2, get_lang('DurationInHours'), false, array('style'=>'width:80px;'));
$table->set_header(3, get_lang('Content'), false);

if (api_is_allowed_to_edit(null, true)) {
$table->set_header(4, get_lang('Actions'), false,array('style'=>'text-align:center'));
$table->set_header(
4,
get_lang('Actions'),
false,
array('style' => 'text-align:center')
);
}
$table->display();
}
2 changes: 1 addition & 1 deletion main/document/create_document.php
Expand Up @@ -521,7 +521,7 @@ function document_exists($filename)
Database::update(
$doc_table,
$params,
[' c_id = ? AND id = ?' => [$course_id, $document_id]]
['c_id = ? AND id = ?' => [$course_id, $document_id]]
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/exercice/answer.class.php
Expand Up @@ -532,7 +532,7 @@ public function updateAnswers(
'hotspot_coordinates' => $hotspot_coordinates,
'hotspot_type' => $hotspot_type,
];
Database::update($answerTable, $params, ['id_auto= ?' => $autoId]);
Database::update($answerTable, $params, ['id_auto = ?' => $autoId]);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion main/exercice/exercise_report.php
Expand Up @@ -185,7 +185,11 @@
'marks' => $my_marks,
'teacher_comment' => $my_comments
];
Database::update($TBL_TRACK_ATTEMPT, $params, ['question_id = ? AND exe_id = ?' => [$my_questionid, $id]]);
Database::update(
$TBL_TRACK_ATTEMPT,
$params,
['question_id = ? AND exe_id = ?' => [$my_questionid, $id]]
);

$params = [
'exe_id' => $id,
Expand Down
24 changes: 17 additions & 7 deletions main/forum/forumfunction.inc.php
Expand Up @@ -543,7 +543,16 @@ function store_forumcategory($values, $courseInfo = array(), $showMessage = true
'cat_title' => $clean_cat_title,
'cat_comment' => $values['forum_category_comment'],
];
Database::update($table_categories, $params, ['c_id = ? AND cat_id = ?' => [$course_id, $values['forum_category_id']]]);
Database::update(
$table_categories,
$params,
[
'c_id = ? AND cat_id = ?' => [
$course_id,
$values['forum_category_id'],
],
]
);

api_item_property_update(
$courseInfo,
Expand Down Expand Up @@ -3394,13 +3403,14 @@ function store_edit_post($values)
}

// Update the post_title and the post_text.
$sql = "UPDATE $table_posts SET
post_title ='".Database::escape_string($values['post_title'])."',
post_text ='".Database::escape_string($values['post_text'])."',
post_notification ='".Database::escape_string(isset($values['post_notification']) ? $values['post_notification'] : null)."'
WHERE c_id = $course_id AND post_id = '".intval($values['post_id'])."'";
$params = [
'post_title' => $values['post_title'],
'post_text' => $values['post_text'],
'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : ''
];
$where = ['c_id = ? AND post_id = ?' => [$course_id, $values['post_id']]];

Database::query($sql);
Database::update($table_posts, $params, $where);

// Update attached files
if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
Expand Down
2 changes: 2 additions & 0 deletions main/inc/lib/database.lib.php
Expand Up @@ -441,6 +441,7 @@ public static function update(
if (!empty($update_sql)) {
//Parsing and cleaning the where conditions
$where_return = self::parse_where_conditions($where_conditions);

$sql = "UPDATE $table_name SET $update_sql $where_return ";

$statement = self::getManager()->getConnection()->prepare($sql);
Expand Down Expand Up @@ -521,6 +522,7 @@ public static function parse_conditions($conditions)
$type_condition = strtolower($type_condition);
switch ($type_condition) {
case 'where':

foreach ($condition_data as $condition => $value_array) {
if (is_array($value_array)) {
$clean_values = array();
Expand Down
4 changes: 2 additions & 2 deletions main/inc/lib/thematic.lib.php
Expand Up @@ -768,10 +768,11 @@ public function thematic_advance_save()
'start_date' => api_get_utc_datetime($start_date),
'duration' => $duration
];

Database::update(
$tbl_thematic_advance,
$params,
[['id = ? AND c_id = ?'] => [$id, $this->course_int_id]]
['id = ? AND c_id = ?' => [$id, $this->course_int_id]]
);

api_item_property_update(
Expand All @@ -781,7 +782,6 @@ public function thematic_advance_save()
"ThematicAdvanceUpdated",
$user_id
);

}

return $last_id;
Expand Down

0 comments on commit a5b4f26

Please sign in to comment.