15 Replies Latest reply on Oct 22, 2008 1:26 AM by Waleed Barakat

    Expire date help

      Hello every one im making a system for my class where students register to this sytems but the expire date the teacher can select if their adtional training will last 15 days, 30 days or 60 days for this i have a table where i register the students, also i have a table where the teacher can add more times and a table of the extra courses or extra weekend class

      example

      table user
      idU int 11 autoincrement primary key
      name varchar 255 and so one with the rest
      grade
      login
      pass
      email
      active
      level

      table times
      idTime
      name (example 15 days class)
      amount (this is where i can add the amount of days)

      table courses
      idCourse
      idU
      idTime
      CourseName
      startdate
      enddate

      i got everything working readed allmost every post on this forums on interkat forums but i have not been able to make a trigger that the end date takes the Startdate and adds from the other table the amount of days to display to the students, your course starts "startdate" and the final exame for it is "enddate" any ideas how can i grab the variable from the table times?? Btw sorry my very bad english.
        • 1. Re: Expire date help
          Waleed Barakat Level 1
          Hi, Miguel
          I guess you have to see this tutorial, I think it can help you in your application...

          :: Please Click Here ::


          __
          Best Regards
          Waleed Barakat
          Developer-Online Creator and programmer
          http://www.developer-online.com
          • 2. Re: Expire date help
            Level 1
            i saw it already and i got almost everything now the point is that the end date, i dont choose it with a date picker like it is in the tutorial, i have a drop donw list that says 15 days 30 days en so one and the values of each are 15, 30 the point im trying to figure out is that it grabs those numbers and does soemthing similiar to this:

            $num_days = (this is suppose to be grabed from teh drop down list from table times)
            enddate = getdate(strtotime("+$num_days day"));

            now one of the problems with this is that it has to use current date ok fine when i us it, but how can i place the variables in the drop down list that has the time of days into $num_days thats the part i have not been able i have checked several costum transaction but all failed.
            • 3. Re: Expire date help
              Level 1
              btw Waleed Barakat your tutorial ROCKS its very good thanks but the only bad thing is that im trying to do something a bit difrent but the counter that u got in ur tutorial i plan to use it here if i ever figure out how to do it :), also my add and edit and list page is made with the dinamic data wizard
              • 4. Re: Expire date help
                Waleed Barakat Level 1
                Hi, Miguel
                thanks for your nice nice comment, i am trying to do my best to help folks and help myself too by sharing my knowledge with them.

                i`ll tell you what i myself learn from every post here in the adobe forums, when i see someone have a problem i do my best to think in a custom solution for it, simply because i might face the same problem.
                • 5. Re: Expire date help
                  Level 1
                  Thanks its really nice from your part wish i had such knowledge like you to also help others well some day :) i been reading the interkat forums and im trying this

                  $query = "SELECT tiempo FROM clastime WHERE idTar = " & KT_escapeForSql(Request.Form("idTar"),"NUMERIC_TYPE")
                  $query_result = $tNG->conection->execute($query);
                  if(!$query_result) {
                  $updateError = new tNG_error("Error setting the initial message ID",array(),array());
                  return $updateError;
                  } else {
                  return NULL;
                  }
                  $fechafin = DateAdd("d", rsValue.Fields.Item("tiempo").Value, Date)
                  tNG_addColumn tNG, "fechafin", "DATE_TYPE", "EXPRESSION", fechafin

                  i have no idea what im doing here but trying to modify what i think could be right lol, i saw it here but its more kind of asp style ill place the link

                  http://www.interaktonline.com/Products/Bundles/MXKollection/Product-Forum/Details/120481/i nsert+an+expire+date.html
                  • 6. Re: Expire date help
                    Waleed Barakat Level 1
                    Hi, Miguel
                    actually i have experienced this process before with one of my best friends "Steven Mark", he faced the same problem as i think but with hard work and sharing some ideas with me he at least found the solution, but i need you to read the full messages we shared to know how!
                    =====================================================================
                    First of all i would like to thank you for creating, showing and explaning how constuct a product expiration. I thought your instructions and images were very good and simple to follow (http://www.developer-online.com/multi_upload/tutorials/part2/produtcs_update.html).

                    I have followed your instuctions in creating something similar, although I have not created a days calculated field in the mysql database as i have used a recordset in dreamweaver to calculate the DATEDIFF(date_expired_pd, current_date) which creates the same but is not adding extra storage to my database.

                    My problem is that in your example the user defines the expiry date.

                    I would like to define the expiry date and not the user but also adding on any extra days that have not yet expired.
                    For example if a user had 2 days until expiry and i gave the opportunity to extend the expiry date for a further 30 days plus the 2 days which have not expired.
                    I have tried to maniuplate the custom trigger but im no expert on this.
                    If you at all have time please could you look at what i have done to the code you have created to determine what i am doing wrong.
                    ==========
                    The code:
                    ==========
                    $exp_timed = $_REQUEST['date_expired_pds'];
                    $query = .KT_DynamicData("{rs.DATEDIFF(date_expired_pd, current_date}");
                    $noDays = $query + $exp_timed;
                    $exp_time = time() + $tNG->getColumnValue("date_activated_pd") + (60 * 60 * 24 * $noDays);
                    $exp_date = KT_formatDate(date ("Y-m-d H:i:s",$exp_time));
                    $tNG->addColumn("date_expired_pd", "DATE_TYPE","EXPRESSION", $exp_date);
                    return $tNG->getError();

                    The problem line is $query = .KT_DynamicData("{rs.DATEDIFF(date_expired_pd, current_date}");
                    I have tried so many varions such as $query = $row_rs['DATEDIFF(flatshares_pd.date_expired_pd, current_date)'];
                    The custom trigger will not allow me to get the DATEDIFF from a recordset as there must be something im leaving out.
                    This one line of code is messing everthing up.
                    If i use a simple $query = "2"; to represent 2 days then it all works. But of course not everyone will have more or less than 2 days to add.
                    ===================
                    Then he found this:
                    ===================
                    $days_extend = $_REQUEST['total_extra_days_to_extend pds'];

                    //selected by registered users
                    $no_days1 = $row_rs2['date_expired_pd'];

                    // currrent expiry date
                    $no_days2 = $row_rs2['date_activated_pd'];

                    // currrent activation date
                    $diff = strtotime($no_days1) - strtotime($no_days2);

                    // difference of expiry date and activation date to be added to new extend date
                    $days_added = $diff/(60*60*24);

                    // difference in days
                    $total_days = $days_added + $days_extend;

                    // non expired days to be added to new expiry date
                    $timeStamp = strtotime($no_days1);

                    // date_activated is current datetime to add the total of extra added days for a new expdate
                    $timeStamp += 24 * 60 * 60 * $total_days;

                    // date_activated plus the extra days constructing a new expiry date
                    $exp_date = date("Y-m-d H:i:s", $timeStamp);

                    // converts timestamp back to appropiate date_time format for mysql
                    echo $exp_date;

                    // USE this line only for TESTING within page Remove for CUSTOM TRIGGER (CT)
                    $tNG ->addColumn(date_expired_pd, NUMERIC_TYPE, EXPRESSION, $noDays);

                    // Use in CT but remove this line for testing.
                    ?>

                    BUT, this script with this added extra line doesnt work
                    $tNG ->addColumn(date_expired_pd, DATE_TYPE, EXPRESSION, $exp_date);

                    Ive tested and tested and what i've found that, the recordsets within a custom trigger can not be called upon outside of the custom trigger using the $no_days1 = $row_rs2['date_expired_pd'];

                    It seems that a custom trigger cuts itself off from recordsets or any other php scripting.
                    Therefore the only thing i can think of to get the code working is to find a method to call on the recordsets via another method. I've researched some methods but have come up with no success. I'm wondering if there is a way to create my own secure recordsets within the custom trigger.

                    The above script works perfectly within a custom trigger when using and fixed dates i enter by removing the call to a recordset.
                    Can you see anything that im doing wrong here. I've just spent over 7 straight hours trying to reslove this ha ha still no joy.
                    ===========================================
                    Finally he came up with the final sloution:
                    ===========================================
                    Hello Waleed,

                    Yahhoooo ive finally mastered it. Thanks for taking a look at the code for me. I include the finalised code i came up with just incase you get a repeat question of mine again lol.

                    If you want any help with what ever issues you are having then please feel free to ask. I probably wont know the answer but my best skill is researching, mixing and matching, testing and evaluating until i get what i want lol, this blinking custom trigger took me over 35 hours to solve but i got ot in the end.
                    Would you mind if i asked you any other random quesions in the future?

                    Thanks again Walled.
                    Steven
                    ============================
                    The mastered code:
                    ============================
                    error_reporting(E_ERROR);

                    $days_extend = $_REQUEST['date_expired_pds'];

                    if ($days_extend == "thirty") {

                    $purchased_days = 30;

                    } else if ($days_extend == "sixty"){

                    $purchased_days = 60;

                    } else if ($days_extend == "ninety"){

                    $purchased_days = 90;

                    } else if ($days_extend == "onehundredeighty"){

                    $purchased_days = 180;

                    } else if ($days_extend == "threesixtyfive"){

                    $purchased_days = 365;

                    }

                    $purchased_days += KT_DynamicData("{rs2. DATEDIFF(flatshares_pd.date_expired_pd, current_date)}");

                    $no_days2 = KT_DynamicData("{rs2.date_expired_pd}");

                    $timeStamp = strtotime($no_days2);

                    $timeStamp += 24 * 60 * 60 * $purchased_days;

                    $newDate = date("d-m-Y H:i:s", $timeStamp);

                    $tNG->addColumn("date_expired_pd", "DATE_TYPE","EXPRESSION", $newDate);
                    ====================
                    hope this help you...
                    • 7. Re: Expire date help
                      Günter Schenk Level 4
                      Hi Waleed,

                      kudos, that was a great job ! :-)

                      One remark though:

                      -------
                      Ive tested and tested and what i've found that, the recordsets within a custom trigger can not be called upon outside of the custom trigger using the $no_days1 = $row_rs2['date_expired_pd'];

                      It seems that a custom trigger cuts itself off from recordsets or any other php scripting
                      -------

                      ADDT´s Custom Triggers encapsulate your code in PHP *functions* after all, and your can indeed import "outside" variables like some recordset value into a function using the GLOBAL keyword

                      Cheers,
                      Günter Schenk
                      Adobe Community Expert, Dreamweaver
                      • 8. Re: Expire date help
                        Waleed Barakat Level 1
                        Hi Gunter
                        thanks, i will add that to my knowledge base, from you we are all learn :-)
                        • 9. Re: Expire date help
                          Level 1
                          ok trying to adapt that one and trying to understand how to modify it for the small system im doing this is what i have right now

                          error_reporting(E_ERROR);
                          $planes = $_REQUEST['planes'];
                          if ($planes == "30") {
                          $tiempo = 30;
                          } else if ($planes == "60"){
                          $tiempo = 60;
                          } else if ($planes == "90"){
                          $tiempo = 90;
                          } else if ($planes == "180"){
                          $tiempo = 180;
                          } else if ($planes == "365"){
                          $tiempo = 365;
                          }

                          $tiempo += KT_DynamicData("{tipo. DATEDIFF(tarifas.tiempo, fecha)}");
                          $no_days2 = KT_DynamicData("{rspagos.fechafin}");
                          $timeStamp = strtotime($no_days2);
                          $timeStamp += 24 * 60 * 60 * $purchased_days;
                          $fechafin = date("Y-m-d", $timeStamp);
                          $tNG->addColumn("fechafin", "DATE_TYPE","EXPRESSION", $fechafin);

                          Ok on my table of courses i got a field called planes this one registers the number of days it will have each course with a drop down menu, on this part im not very sure what to place here $tiempo += KT_DynamicData("{tipo. DATEDIFF(tarf.tiempo, fecha)}"); for now im supposing that tipo (is the query where i have the time plans) and tarf.tiempo is the colum that saves the number of days of the plan, fecha is in the other hand on the other table of the courses with gets the current date with a {NOW}, fechafin is the expire date or where i want to save it inside the table of courses and rspagos is the query which calls the table courses placed that name trying to follow some other tutorials but its not a pay tables only registers the name of the course the time the person register it, the expire date and an observation field o and an active or descative field, now testing this i just get the fechafinal has 0000-00-00, ill keep trying to understand it but i guess im in the correct path.
                          • 10. Re: Expire date help
                            Waleed Barakat Level 1
                            Hi Miguel
                            if you get 0000-oo-oo you might be in the right course as you said, also did you checked the Database Date Format in the ADDT control panel???

                            i said that because you may insert the date value in other format like 00-00-0000 which is mean [date-month-year] and the database accept only [0000-00-00] which is [year-month-date].

                            try to check that first...
                            • 11. Re: Expire date help
                              Level 1
                              yes i have changed the date way on the trigger testing if it was that from

                              $fechafin = date("Y-m-d", $timeStamp); also try
                              $fechafin = date("d-m-Y", $timeStamp);
                              $fechafin = date("m-d-Y", $timeStamp);

                              but they all give me 0000-00-00 :(
                              • 12. Re: Expire date help
                                Level 1
                                ok got some question about the last part in order to see if im understanding it and sorry so many questions,

                                error_reporting(E_ERROR);

                                //on my table planes is wher it stores the amount of time theres a drop down list on my form to pick the amount of date is it correct to use it with the request or this request comes from a url variable?
                                $planes = $_REQUEST['planes'];

                                //on this part if ($planes == "a number" on my drop down the display field shows the number of time so i set a new variable called time or tiempo in my language and asign here the amount?
                                if ($planes == "30") {
                                $tiempo = 30;
                                } else if ($planes == "60"){
                                $tiempo = 60;
                                } else if ($planes == "90"){
                                $tiempo = 90;
                                } else if ($planes == "180"){
                                $tiempo = 180;
                                } else if ($planes == "365"){
                                $tiempo = 365;
                                }

                                //this part i dont understand what everything does and im not sure if i have the correct fields
                                $tiempo += KT_DynamicData("{tipo. DATEDIFF(tarifas.tiempo, fecha)}");

                                //same on this part the rspagos im trying to guess its the principal query made but the form wizard thast why i have rspagos. and the column name where at this point i think its still empty (fechafin) wich is where i want to store the expire date
                                $no_days2 = KT_DynamicData("{rspagos.fechafin}");

                                $timeStamp = strtotime($no_days2);

                                $timeStamp += 24 * 60 * 60 * $tiempo;

                                $fechafin = date("Y-m-d", $timeStamp);

                                $tNG->addColumn("fechafin", "DATE_TYPE","EXPRESSION", $fechafin);

                                lol this has become really frustrating wish i had more knoledge on using triggers, but well if i get this any day ill try to make a manual like Waleed Barakat if he allows me to place it on his site cause i dont have where to place any tutorial or manuals, and school doesnt allow me to upload things like that.

                                guys please let me know if im going good or any suggestions what to change there i feel stuck lol
                                • 13. Re: Expire date help
                                  Waleed Barakat Level 1
                                  Hi miguel
                                  you are welcome to post things you discovered and maybe helpful for others as a reference. :-)
                                  • 14. Re: Expire date help
                                    Level 1
                                    Thanks Waleed,

                                    Well after 2 days of testing and trying and trying waleed gave me the shot i mixed both codes u placed here and from your tutorial and finally got this

                                    -----------------------------------------------------------------
                                    -----------------------------------------------------------------
                                    error_reporting(E_ERROR);
                                    // this is from waleed tutorials on getting the value of a form field
                                    //
                                    $planesx = $tNG->getColumnValue("planes");
                                    // this part is from the discution with waleed friend Steven Mark
                                    //
                                    if ($planesx == "30") {
                                    $tiempox = 30;
                                    } else
                                    if ($planesx == "60"){
                                    $tiempox = 60;
                                    } else
                                    if ($planesx == "90"){
                                    $tiempox = 90;
                                    } else
                                    if ($planesx == "180"){
                                    $tiempox = 180;
                                    } else
                                    if ($planesx == "365"){
                                    $tiempox = 365;
                                    }
                                    /* finaly and this is what adds into my expire date field searching many pages to end up with this at php.net/date grabing the variable to add more days to the date */
                                    $datex = date("d-m-Y", strtotime("+".$tiempox. "days"));
                                    $tNG->addColumn("fechafin", "DATE_TYPE","EXPRESSION", $datex);
                                    -----------------------------------------------------------------
                                    -----------------------------------------------------------------

                                    hope this helps other it was not quite the way i planed but 2 days already doing this for a proyect class and i feel ill be more stuck if i keep doing it more automized.

                                    Thanks Waleed for taking your time to help me here many thanks man.
                                    • 15. Re: Expire date help
                                      Waleed Barakat Level 1
                                      Well Done, you are the man, searching, exploring, consulting, and mixing codes then finally you find what you are looking for. it's the best solution for every problem you might face in the future.

                                      also Gunter give us a glance of hope here by commenting the Custom_Trigger. thank you Gunter...