Advertisement
badlogic

code for select2 add and edit

Mar 17th, 2017
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?=var_dump($college_subject_data['prereqsnew'])?>
  2. <?/*=var_dump($college_subject_data['prereqs'])*/?>
  3. <?php $prerequsit_id = $college_subject_data['prereqs2'];
  4.  
  5. var_dump($prerequsit_id);
  6. ?>
  7.  
  8. <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.css"/>
  9. <script src="http://cdnjs.cloudflare.com/ajax/libs/select2/3.2/select2.min.js"></script>
  10.  
  11.  
  12.  
  13.  
  14.  
  15. <div class="sublist">
  16.     <fieldset class="themeFieldset01">
  17.         <legend class="themeLegend01">Subjects</legend>
  18.         <?php
  19.         if(isset($eMsg)){
  20.             if (is_array($eMsg)) {
  21.                 ?>
  22.                 <div class="tblListErrMsg">
  23.                     <?php
  24.                     foreach ($eMsg as $key => $value) {
  25.                         ?>
  26.                         &nbsp;&nbsp;&bull;&nbsp;<?=$value?><br>
  27.                     <?php
  28.                     }
  29.                     ?>
  30.                 </div>
  31.             <?php
  32.             }else {
  33.                 ?>
  34.                 <div class="tblListErrMsg">
  35.                     <?=$eMsg?>
  36.                 </div>
  37.             <?php
  38.             }
  39.         }
  40.         ?>
  41.  
  42.         <?php
  43.         //printa ($oData);
  44.         //printa ($subjectdata);
  45.         ?>
  46.         <form method="post" action="">
  47.             <input type="hidden" name="college_course_id" value="<?=$_GET['cc_id']?>"/>
  48.             <div style="padding:5px;"><!-- background:#FFFFFF; -->
  49.                 <fieldset class="themeFieldset01" style="background-color:#a4dd80">
  50.                     <table width="100%">
  51.                         <tr>
  52.                             <td width="80%">
  53.                                 <table width="100%" cellpadding="3" cellspacing="1">
  54.                                     <tr>
  55.                                         <td width="15%" class="tablecell_dark" style="font-weight: bold;">Course</td>
  56.                                         <td width="3%" align="center">:</td>
  57.                                         <td width="">
  58.                                             <?=$currentsemdata['cc_name']?></b>
  59.                                         </td>
  60.                                     </tr>
  61.                                     <tr>
  62.                                         <td class="tablecell_dark" style="font-weight: bold;">Year Level</td>
  63.                                         <td align="center">:</td>
  64.                                         <td width="">
  65.                                             <?=$currentsemdata['yl_name']?></b>
  66.                                         </td>
  67.                                     </tr>
  68.                                     <tr>
  69.                                         <td class="tablecell_dark" style="font-weight: bold;">Semester</td>
  70.                                         <td align="center">:</td>
  71.                                         <td width="">
  72.                                             <?=$currentsemdata['cs_name']?></b>
  73.                                         </td>
  74.                                     </tr>
  75.                                     <tr>
  76.                                         <td class="tablecell_dark" style="font-weight: bold;">Subject Name</td>
  77.                                         <td align="center">:</td>
  78.                                         <td width="">
  79.  
  80.                                             <input type="hidden" name="csh_id" id="searchInput" />
  81.                                             <input type="text" name="search_label" id="searchInputLabel" />
  82.  
  83.                                             <!--<select name="csh_id">s
  84.                                                 <option value="0">Select Subject</option>
  85.                                                 <?/*= html_options_2d($college_subject_list, "college_headers_subject_id", "subjname_name", $college_subject_data['csh_id'], false) */?>
  86.                                             </select>-->
  87.  
  88.                                             <a href="javascript:void;" onclick="javascript:openwindow('registrar.php?statpos=course_curriculum&action=search_subject_curr&cc_id=<?=$_GET['cc_id']?>&ccch_id=<?=$_GET['ccch_id']?>', 'change', '');" >Search</a>
  89.  
  90.                                         </td>
  91.                                     </tr>
  92.                                     <tr>
  93.                                         <td class="tablecell_dark" style="font-weight: bold;">Lecture Units</td>
  94.                                         <td align="center">:</td>
  95.                                         <td><input type="text" name="lec_unit" value="<?= $college_subject_data['lec_unit'] ?>"/>
  96.                                         </td>
  97.                                     </tr>
  98.                                     <tr>
  99.                                         <td class="tablecell_dark" style="font-weight: bold;">Laboratory Units</td>
  100.                                         <td align="center">:</td>
  101.                                         <td><input type="text" name="lab_unit" value="<?=$college_subject_data['lab_unit'] ?>"/>
  102.                                         </td>
  103.                                     </tr>
  104.                                     <tr>
  105.                                         <td class="tablecell_dark" style="font-weight: bold;">Prerequisite</td>
  106.                                         <td width="5%" align="center">:</td>
  107.  
  108.                                         <td>
  109.                                             <table class="table" id="prerequisites">
  110.                                                 <?/*=$college_subject_data['prereqs'] */?>
  111.  
  112.  
  113.                                                 <!--ccaburog prerequsites-->
  114.  
  115.                                                 <select multiple id="e1" style="width:700px">
  116.  
  117.                                                 </select>
  118.  
  119.  
  120.                                                 <!--ccaburog prerequsites-->
  121.  
  122.  
  123.                                             </table>
  124.                                         </td>
  125.                                     </tr>
  126.                                     <tr>
  127.                                         <td>&nbsp;</td>
  128.                                         <td align="center"><input type="hidden" name="prereqs" id="prereqs" value=""></td>
  129.  
  130.                                         <td style="display: none">
  131.                                             <a href="javascript:void;" onclick="javascript:openwindow('registrar.php?statpos=course_curriculum&action=prerequisites&cc_id=<?=$_GET['cc_id']?>&ccch_id=<?=$_GET['ccch_id']?>', 'change', '');" >+add prerequisite</a> |
  132.                                             <a href="javascript:void;" onclick="deleteRow();">-delete last prerequisite</a>
  133.                                         </td>
  134.                                     </tr>
  135.                                     <tr>
  136.                                         <td class="tablecell_dark" style="font-weight: bold;">Order</td>
  137.                                         <td align="center">:</td>
  138.                                         <td><input type="text" name="ccc_order" value="<?= $college_subject_data['ccc_order'] ?>"/>
  139.                                         </td>
  140.                                     </tr>
  141.                                     <tr>
  142.                                         <td class="tablecell_dark" style="font-weight: bold;">Include to total units</td>
  143.                                         <td align="center">:</td>
  144.                                         <td>
  145.                                             <input type="checkbox" value="20" <?=$college_subject_data['ischecked']?> name="is_included">
  146.                                         </td>
  147.                                     </tr>
  148.                                     <tr>
  149.                                         <td>
  150.                                             &nbsp;
  151.                                         </td>
  152.                                         <td align="center">&nbsp;</td>
  153.                                         <td>
  154.                                             <?php
  155.                                             if($_GET['action']=="editsemsubject"){
  156.                                                 ?>
  157.                                                 <input type="submit" name="addSubject" value="Save" />
  158.                                             <?php
  159.                                             } else {
  160.                                                 ?>
  161.                                                 <input type="submit" name="addSubject" value="Add Subject"/>
  162.                                             <?php
  163.                                             }
  164.                                             ?>
  165.                                         </td>
  166.                                     </tr>
  167.  
  168.                                     <!--week-->
  169.                                 </table>
  170.                             </td>
  171.                             <td>
  172.                                 <!--                                <table width="100%">-->
  173.                                 <!--                                    <tr>-->
  174.                                 <!--                                        <td width="20%">-->
  175.                                 <!--                                            Lecture Units-->
  176.                                 <!--                                            --><?php
  177.                                 //                                            printa($total_unit);
  178.                                 //                                            ?>
  179.                                 <!--                                        </td>-->
  180.                                 <!--                                        <td width="3%">-->
  181.                                 <!--                                            :-->
  182.                                 <!--                                        </td>-->
  183.                                 <!--                                        <td>-->
  184.                                 <!--                                            --><?//=$total_unit['ilec']?><!--/--><?//=$total_unit['lec']?>
  185.                                 <!--                                        </td>-->
  186.                                 <!--                                    </tr>-->
  187.                                 <!--                                    <tr>-->
  188.                                 <!--                                        <td>-->
  189.                                 <!--                                            Laboratory Unit-->
  190.                                 <!--                                        </td>-->
  191.                                 <!--                                        <td>-->
  192.                                 <!--                                            :-->
  193.                                 <!--                                        </td>-->
  194.                                 <!--                                        <td>-->
  195.                                 <!--                                            --><?//=$total_unit['ilab']?><!--/--><?//=$total_unit['lab']?>
  196.                                 <!--                                        </td>-->
  197.                                 <!--                                    </tr>-->
  198.                                 <!--                                </table>-->
  199.                             </td>
  200.                         </tr>
  201.                     </table>
  202.  
  203.                 </fieldset>
  204.                 Lists of All Subjects under <b><?=$currentsemdata['cc_name']?></b>
  205.             </div>
  206.         </form>
  207.     </fieldset>
  208. </div>
  209. <?=$sem_subject_list?>
  210.  
  211.  
  212. <script language="JavaScript">
  213.  
  214.     function deleteRow() {
  215.         table = document.getElementById("prerequisites");
  216.         rowcount = table.rows.length;
  217.         table.deleteRow(rowcount - 1);
  218.  
  219.         json1 = JSON.parse(document.getElementById('prereqs').value);
  220.         //console.log(json1);
  221.         /*console.log(JSON.stringify(json1.slice(0,-1));*/
  222.         document.getElementById('prereqs').value = JSON.stringify(json1.slice(0,-1));
  223.     }
  224. </script>
  225.  
  226.  
  227. <script>
  228.     $("#e1").select2();
  229.     $("#e1").select2({
  230.         placeholder: "Select a Subjects"
  231.     });
  232.  
  233.  
  234.  
  235.  
  236.  
  237.     <?php
  238.  
  239.         if(isset($_GET['ccc_id'])){
  240.  
  241.     ?>
  242.     //$('#e1').select2('data', {id: 100, value: 'Lorem Ipsum'});
  243.  
  244.  
  245.     //split the data
  246.  
  247.     var s = "<?=$college_subject_data['prereqsnew']?>";
  248.     var y = "<?=$college_subject_data['prereqs2new']?>";
  249.     var matchs = s.split(',');
  250.     var matchy = y.split(',');
  251.     console.log(matchs)
  252.     console.log(matchy)
  253.  
  254.  
  255.  
  256.     var array = "";
  257.     var ctr = 0;
  258.     var person = [];
  259.     var array = "";
  260.     var test = "";
  261.     var sampleArray = [];
  262.  
  263.     var dataArrayEdit = [];
  264.  
  265.  
  266.     for (var a in matchs)
  267.     {
  268.         var variablesLable = matchs[a];
  269.         var variableyValue = matchy[a];
  270.  
  271.         // sampleArray = [{text:variablesLable,value:variableyValue}];
  272.         sampleArray.push( { text: variablesLable, value:variableyValue, id:variableyValue} );
  273.  
  274. //        /dataArrayEdit.push($("#e1").select2('data')[ctr].value);
  275.  
  276.  
  277.         ctr++;
  278.     }
  279.  
  280.     //console.log(dataArrayEdit);
  281.     // console.log('sample array',sampleArray);
  282.  
  283.  
  284.     //var strdata = array.slice(',', -1);
  285.  
  286.  
  287.     // var sampleArray = [{id:0,text:'enhancement'}, {id:1,text:'bug'}];
  288.  
  289.  
  290.  
  291.     $("#e1").select2( 'data',
  292.         sampleArray
  293.     );
  294.  
  295.     <?php
  296.  
  297.         }
  298.  
  299.      ?>
  300.  
  301.     var editArray = [];
  302.     var data0 = 0;
  303.     var data1 = 0;
  304.     var test = 0;
  305.     var temp = 0;
  306.     var tempStorage = [];
  307.     var detailsEdit = $("#e1").select2('data');
  308.  
  309.     var xyz = 1;
  310.  
  311.  
  312.  
  313.  
  314.     console.log('temp storage',tempStorage);
  315.  
  316.  
  317.     window.setInterval(function(){
  318.  
  319.         var x = 0;
  320.         //console.log(preRequisitesSubjects());
  321.         console.log($("#e1").select2('data')[0].id);
  322.         <?php
  323.          if(isset($_GET['ccc_id'])){
  324.          ?>
  325.  
  326.  
  327.         test = Object.keys($("#e1").select2('data')).length;
  328.         console.log('cont data object',test);
  329.         console.log('cont data object this---->',$("#e1").select2('data'));
  330.  
  331.         while(x < test){
  332.  
  333.             var wew = $("#e1").select2('data')[x].id;
  334.             tempStorage.push($("#e1").select2('data')[x].id);
  335.            // tempStorage = $("#e1").select2('data')[x].id;
  336.             var t = $("#e1").select2('data')[x].id;
  337.  
  338.  
  339.             x++;
  340.  
  341.         }
  342.  
  343.         console.log('x',x);
  344.         console.log('t',t);
  345.         console.log('wew',wew);
  346.  
  347.         console.log('tem storage',tempStorage);
  348.  
  349.  
  350.  
  351.         document.getElementById('prereqs').value="["+tempStorage+"]";
  352.  
  353.         tempStorage = [];
  354.  
  355.  
  356.         <?php }else{ ?>
  357.  
  358.  
  359.  
  360.         document.getElementById('prereqs').value="["+$("#e1").val()+"]";
  361.  
  362.         <?php } ?>
  363.  
  364.     }, 1000);
  365.  
  366.  
  367.     window.onload = function() {
  368.         console.log(preRequisitesSubjects());
  369.     };
  370.  
  371.     function preRequisitesSubjects()
  372.     {
  373.         $.ajax({
  374.             url: "registrar.php?",
  375.             type: "GET",
  376.             data:  {
  377.                 statpos: 'course_curriculum',
  378.                 action: 'prerequisites',
  379.                 cc_id: <?=$_GET['cc_id']?>,
  380.                 ccch_id: <?=$_GET['ccch_id']?>,
  381.                 ajax_prerequisites: '1'
  382.             },
  383.             success: function(data){
  384.  
  385.                 data.forEach(function(data){
  386.                     console.log(data);
  387.                     document.getElementById("e1").innerHTML +=
  388.                         "<option value="
  389.                         +data.ccc_id
  390.                         +">"
  391.                         +data.subjname_shortname
  392.                         +" - "
  393.                         +data.subjname_name
  394.                         +" </option>";
  395.  
  396.                 });
  397.  
  398.             },
  399.             dataType: 'json'
  400.         });
  401.     }
  402.  
  403.  
  404. </script>
  405.  
  406. <!--sample-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement