added condition for empty ids.
Showing
2 changed files
with
57 additions
and
7 deletions
... | @@ -49,7 +49,12 @@ switch ($action) { | ... | @@ -49,7 +49,12 @@ switch ($action) { |
49 | $instance->cmid = $madatorycmids; | 49 | $instance->cmid = $madatorycmids; |
50 | $instance->mandatory = $mandatoryactivities->mandatory; | 50 | $instance->mandatory = $mandatoryactivities->mandatory; |
51 | 51 | ||
52 | $DB->update_record('local_mandatory_activities', $instance); | 52 | if (!empty($madatorycmids)){ |
53 | $DB->update_record('local_mandatory_activities', $instance); | ||
54 | }else{ | ||
55 | $sql="delete from mdl_local_mandatory_activities where course=$course"; | ||
56 | $DB->execute($sql); | ||
57 | } | ||
53 | 58 | ||
54 | }else{ | 59 | }else{ |
55 | 60 | ||
... | @@ -84,7 +89,7 @@ switch ($action) { | ... | @@ -84,7 +89,7 @@ switch ($action) { |
84 | $allcmids[]=$value->id; | 89 | $allcmids[]=$value->id; |
85 | } | 90 | } |
86 | 91 | ||
87 | if ($mandatoryids && $checkedids){ | 92 | if ($mandatoryids || $checkedids){ |
88 | 93 | ||
89 | $previousestatus=explode(",",$mandatoryids); | 94 | $previousestatus=explode(",",$mandatoryids); |
90 | foreach($checkedids as $id){ | 95 | foreach($checkedids as $id){ |
... | @@ -140,7 +145,41 @@ switch ($action) { | ... | @@ -140,7 +145,41 @@ switch ($action) { |
140 | $unchangedactivities[]=$aname; | 145 | $unchangedactivities[]=$aname; |
141 | } | 146 | } |
142 | } | 147 | } |
143 | }else{ | 148 | }else if ($checkedids) { |
149 | |||
150 | foreach($checkedids as $id){ | ||
151 | |||
152 | if (isset($qresult[$id])){ | ||
153 | $id=number_format($id); | ||
154 | $modaname=$qresult[$id]->name; | ||
155 | $instance=$qresult[$id]->instance; | ||
156 | |||
157 | $sqlactivityname="select name from mdl_$modaname where id=$instance"; | ||
158 | $aname=$DB->get_record_sql($sqlactivityname); | ||
159 | |||
160 | $newlyaddedactivities[]=$aname; | ||
161 | $newlyaddedids[]=$id; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | $res=array_diff($allcmids,$newlyaddedids); | ||
166 | $unchangedids=array_diff($res,$removedids); | ||
167 | |||
168 | foreach ($unchangedids as $data){ | ||
169 | if (isset($qresult[$data])){ | ||
170 | $id=number_format($data); | ||
171 | $modaname=$qresult[$data]->name; | ||
172 | $instance=$qresult[$data]->instance; | ||
173 | |||
174 | $sqlactivityname="select name from mdl_$modaname where id=$instance"; | ||
175 | $aname=$DB->get_record_sql($sqlactivityname); | ||
176 | |||
177 | $unchangedactivities[]=$aname; | ||
178 | } | ||
179 | } | ||
180 | |||
181 | } | ||
182 | else{ | ||
144 | 183 | ||
145 | foreach ($qresult as $val){ | 184 | foreach ($qresult as $val){ |
146 | $modaname=$val->name; | 185 | $modaname=$val->name; | ... | ... |
... | @@ -128,14 +128,19 @@ th,td{ | ... | @@ -128,14 +128,19 @@ th,td{ |
128 | 128 | ||
129 | $(document).on('click', '#savemandatory', function(){ | 129 | $(document).on('click', '#savemandatory', function(){ |
130 | 130 | ||
131 | $('#madatorysection').css("display", "none"); | ||
132 | $('#loadingcomparision').css("display", "block"); | ||
133 | |||
134 | var checkedids=[]; | 131 | var checkedids=[]; |
135 | 132 | ||
136 | $('input:checkbox.checkboxesavilable:checked').each(function () { | 133 | $('input:checkbox.checkboxesavilable:checked').each(function () { |
137 | checkedids.push($(this).attr("data-cmid")); | 134 | checkedids.push($(this).attr("data-cmid")); |
138 | }); | 135 | }); |
136 | |||
137 | |||
138 | // if(checkedids.length > 0){ | ||
139 | |||
140 | $('#madatorysection').css("display", "none"); | ||
141 | $('#loadingcomparision').css("display", "block"); | ||
142 | |||
143 | |||
139 | 144 | ||
140 | var rootPath = M.cfg.wwwroot; | 145 | var rootPath = M.cfg.wwwroot; |
141 | var arg = { action:'getcomparision', | 146 | var arg = { action:'getcomparision', |
... | @@ -220,6 +225,12 @@ th,td{ | ... | @@ -220,6 +225,12 @@ th,td{ |
220 | 225 | ||
221 | } | 226 | } |
222 | }); | 227 | }); |
228 | |||
229 | // }else{ | ||
230 | |||
231 | // alert("Please do select atleast one activity to proceed"); | ||
232 | |||
233 | // } | ||
223 | 234 | ||
224 | // $('#accordion1').css("display", "none"); | 235 | // $('#accordion1').css("display", "none"); |
225 | 236 | ||
... | @@ -267,7 +278,7 @@ th,td{ | ... | @@ -267,7 +278,7 @@ th,td{ |
267 | 278 | ||
268 | $('#loadingcomparision').css("display", "none"); | 279 | $('#loadingcomparision').css("display", "none"); |
269 | 280 | ||
270 | var alerttags='<div class="alert alert-success"><strong>Successfully Ssved</strong></div>'; | 281 | var alerttags='<div class="alert alert-success"><strong>Successfully Saved</strong></div>'; |
271 | $('#successalert').append(alerttags); | 282 | $('#successalert').append(alerttags); |
272 | 283 | ||
273 | setTimeout(function(){ | 284 | setTimeout(function(){ | ... | ... |
-
Please register or sign in to post a comment