ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

CGIDEV2 to present JPGs stored on the IFS?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CGIDEV2 to present JPGs stored on the IFS?

    Hi all,

    Background Info and Goal

    We have about 7500 product image JPGs stored in one folder on the IFS. Each filename is 123456789.JPG, where 123456789 is the SKU number. For each one, there is also a thumbnail image named TN_123456789.JPG in that same folder, so the folder actually contains about 15000 image files. Each SKU in our part master has an associated product class, such as 1234.

    I would like to create a system where an initial HTML page shows all the classes as links. Clicking on one of those class links would display an HTML page showing all the SKU thumbnail images in that class, along with the SKU as a clickable link. Clicking on a SKU would display an HTML page with the full size product image along with some associated info from the product master, such as the vendor number and name.

    I'm thinking that maybe CGIDEV2 might be the way to go to accomplish all this. I have not created HTML directly from RPG before, but I'm currently reading through Scott Klement's presentation on his website. CGIDEV2 has never been used here, but it was used once where I used to work in order to create some XML files on the IFS.

    Questions

    1. Where is the best place to download CGIDEV2? (I notice I can get it from IBM or from Easy400.net). Do you agree that CGIDEV2 is the way to go?

    2. From what I've described, do you think it's easiest and/or best to create in batch a bunch of static HTML pages (one for every SKU, so each would be named 123456789.HTML) where the only difference is the SKU number, image link, and vendor info, or is it best to create one template SKU HTML file where I substitute in the SKU number and related info dynamically? The latter seems better to me but maybe more complicated because I'd need to run RPG from the web page whenever they navigate to a new SKU, etc., rather than just creating all the individual HTML files in a batch process upfront and being done with it.

    I'm thinking a sample HTML file for a SKU would look something like this when displayed:

    Code:
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Refresh"CONTENT="1800;URL=123456789.HTML">
    </HEAD>
    <BODY>
    </TABLE>
    <TABLE WIDTH=100% HEIGHT=3  BGCOLOR="#082984">
    <TR><TD><FONT COLOR="#082984"></FONT>
    </TABLE>
    <H1>123456789 Product Description for this SKU</H1>
    <TABLE WIDTH=100% ALIGN=TOP>
    <TR><TD><IMG SRC="images/123456789.JPG" ALIGN=LEFT WIDTH=550 HEIGHT=365></TR></TD>
    <TD>CLASS: 1234<BR> Class Description for this Class<BR><BR>
    VENDOR: 12345<BR> Vendor Name<BR><BR>
    </TD>
    </TABLE>
    </BODY>
    </HTML>
    Would love some feedback/guidance on this before I get myself too far down the wrong path, especially from someone who has done something similar in the past... Thanks!

  • #2
    Re: CGIDEV2 to present JPGs stored on the IFS?

    I think it's valuable to learn HTML and understand how it works, etc. However, I would use CSS styling rather than old, deprecated, techniques like the <font> tag or 'align=left'. I would aim to comply with HTML5.

    Having said that... having a program generate an html page that gets re-loaded with every click is the "web 1.0" way of doing things. Still works and is widely used today, but perhaps you would be better served by using the "web 2.0" approach? Use JavaScript (possibly with a framework) to update just parts of the screen as they change?

    As to whether you use CGIDEV2... I see nothing wrong with that approach. But, please understand that no matter whether this is CGIDEV2 or RPGsp or JSP or PHP, etc... in any of these cases you'll write and code the exact same html, css, javascript, etc. All of these techniques can be used with either the web 1.0 or web 2.0 approach. The web code will be exactly the same no matter the environment. The only thing that will be different is the server-side code in which you do your business logic and other calculations. So the decision of whether to use CGIDEV2 or similar really depends on whether your logic is better suited to RPG (which is strong in database and business math type work, but really only available for IBM i) or PHP (which is cross-platform and strong in string handling, but much weaker in business logic, database, business math) or any of the other alternatives...

    Also, I would add that this thread could easily turn into a "holy war" where everyone shouts about how their favorite language is better than the others... I really hope that does not happen.

    Comment


    • #3
      Re: CGIDEV2 to present JPGs stored on the IFS?

      The code management would be horrendous if you had 7500 pages that have to change for every small thing. To write one page to handle all of the products might be more work up front, but you will thank yourself every time you change just one page to fix something little. If you are on 6.1 or above check out this article from Aaron Bartell in iprodeveloper(free registration) http://iprodeveloper.com/application...-handle-rpg-oa, and you said you were already reading one of Scott's articles. With those two guys articles you shouldn't have a problem coming up with something fancy.

      Comment


      • #4
        Re: CGIDEV2 to present JPGs stored on the IFS?

        Hi,

        Question 1: CGIDEV2 can be downloaded from:

        1. IBM, but this version has been frozen since 2007
        2. Easy400 group, this is a ?clean CGIDEV2? version
        3. Renaissance Framework, a jQuery based framework

        4. powerEXT Core and Framework, a EXT JS based framework
        http://powerEXT.com (this is BTW my framework)

        There are a lot of other possibilities (not CGIDEV2 based) where most can be found here:



        Question 2: No, you should generate HTML at the fly. There is no reason to have to maintain 7500 html pages to display JPG?s

        General: I think that there are several things you have to consider first:

        1. Who are the users (Internal *OS or external)?
        2. Should the system protect the application with passwords?
        3. Will it be public on the net?
        4. What kind of devices may the app run on (desktop/touch)?
        5. Do you also need to display the pictures from 5250?
        6. Do you need other browser based functions (long term)?
        7. What are your present skills in web development and do you have OO skills?
        8. Should the code be server platform independent?

        I agree with Scott that you should not chose to code the client side in Web 1.0 HTML since the application will look and feel old. The simple way is to code HTML5, CSS3 and use AJAX. The more sophisticated way is to learn and use either jQuery, DOJO, EXT JS or another javascript based client framework but these framework will require (self)education ? on the other hand they comes with CSS3 themes.

        The easiest way is to use one of the many frameworks listed above where some are free, some has a free community version and some are commercial. All these frameworks have their pros and cons but common for all is that they the saves development time and gives you better functionality in the UI.

        Why HTML5/CSS3.

        A traditional display of a picture from a list or a gallery would look like this in WEB 1.0 where the system will open a new browser window to display the picture:



        The same in HTML5/CSS3 could look like this (the gallery could also be a list of data) Just click on the pictures to enlarge:



        Here is another little appetizer on WEB 2.0 ? well it may be far out to steam videos from a standard file maintenance program on record level while you can work in the others ? but is just a demonstration what you are able to do in web 2.0

        Feel free to click on the thumbnail pictures from the gallery in the grid while watching the video ?

        Comment


        • #5
          Re: CGIDEV2 to present JPGs stored on the IFS?

          BTW

          I hope not to have started a "holy war" - the secret is in the HTML/CSS/javascript code and NOT in the server code!

          Comment


          • #6
            Re: CGIDEV2 to present JPGs stored on the IFS?

            Hi again, and thanks for your responses and insight.

            Yes, I am aware that the simplistic approach I was presenting as a possibility is extremely Web 1.0. At my last job, we had CNX Valence and were making some really great applications that were dynamic and interactive and looked amazing. I didn't become an expert in it before leaving, but I could create some nifty stuff using their templates. Where I am now, things have been very old school. When I arrived, they were only programming in RPG/400 even though we're on i7.1. I have introduced free-format RPG with embedded SQL, procedures and service programs, etc.

            For this project, some fun and cool things could certainly be done. But the very basic need is just to display the images. I was even thinking I could just use a photo gallery software like JAlbum or something, except that I need the images to be grouped by class code, and they currently aren't in subfolders by class, but instead all in one folder. So the most basic info I need from the IBM i is the class of the SKU. Getting the vendor while I'm at it might be nice too but not critical.

            The code management would be horrendous if you had 7500 pages that have to change for every small thing.
            The pages would never have to change as they just have the SKU and the image. They never change class code. But even if something did change (such as if I am displaying the vendor and it changed), I would still never maintain 7500 HTML pages... I agree that would be horrendous. I would just re-run my batch process which would re-create all the Web 1.0 pages with the latest info. I'm not saying this is the right way to go, I'm just saying that I wouldn't be maintaining any HTML pages individually.

            Henrik,

            I've seen you present things that your powerEXT Core can do, and it looks very cool. I also liked the examples you posted - thanks. The last Web 2.0 reminds me of the things we did with CNX Valence where the users could sort or re-arrange columns, etc.

            1. Who are the users (Internal *OS or external)?
            2. Should the system protect the application with passwords?
            3. Will it be public on the net?
            4. What kind of devices may the app run on (desktop/touch)?
            Internal users, not out on the net, no password necessary, Desktop browser.

            5. Do you also need to display the pictures from 5250?
            Yes I do this now from several 5250 screens by starting the browser and bringing up the image.

            6. Do you need other browser based functions (long term)?
            I can imagine doing some cool stuff further out in the future, like making a full-featured product master including the images, etc. For now, I just need to let them navigate to a class, click on a SKU, and see the image.

            7. What are your present skills in web development and do you have OO skills?
            Some experience with CNX Valence, but no OO.

            8. Should the code be server platform independent?
            I do not see this as necessary.

            Anyway, for my immediate and most basic need, my question was basically whether I could use CGIDEV2 to programmatically create simple HTMLs for each image using a template HTML file with substitution variables (a Web 1.0 solution as you say). And I believe it can do that, correct?

            But you guys have also got me thinking about cooler stuff.

            Comment


            • #7
              Re: CGIDEV2 to present JPGs stored on the IFS?

              Ok Viking, I was doing some other experimentation with CGIDEV2 to come up to speed (as usual found the answer in a Scott Klement post) and saw your thread which gave me another thing to check out. First though I ran across this link from Paul Tuohy which is very helpful to your goals: http://search400.techtarget.com/tip/...CGIDEV2-Part-3

              Now, as far as answering your question about using CGIDEV2, I'll post my little test code here. Point here of this test is that minimal html snippet of img src has IFS file name set before showing the page. I did this as a parm where I just paste the parm into a file name (32 char max) variable in my CGIDEV2 template file. So it displays whatever image file name is typed in the url parm ( e.g. http://IBMiurl/cgiserver/helloimg?img=TN_123456789.JPG ) Also I am running the cgi server on one port and using apache on port 80 to show image file from document root folder, in other words, all defaults and minimal file path.

              HELLOIMG RPG CGIDEV2 program
              Code:
              [FONT=Courier New]      *****************************************************************
                    *                      CGIDEV2 Testing
                    *
                    *  Program HELLOIMG
                    *****************************************************************
                   h  dftactgrp(*no) actgrp('RDWRITES')
                   h bnddir('CGIDEV2':'QC2LE':'QUSAPIBD')
                   h optimize(*none) decedit(*jobrun) truncnbr(*no)
                   h debug option(*srcstmt:*nodebugio)
              
                    *****************************************************************
                    * Prototype Definitions
                    *****************************************************************
                    /copy cgidev2/qrpglesrc,prototypeb
              
                    *****************************************************************
                    * *Entry Declaration
                    *****************************************************************
                   d HELLOIMG        pr
                   d HELLOIMG        pi
              
                    *****************************************************************
                    * Data Structure Declaration
                    *****************************************************************
                   d qusec           ds
                   d  qusbprv                            like(int32) inz(%size(qusec))        Bytes Provided
                   d  qusbavl                            like(int32) inz(0)                   Bytes Available
                   d  qusei                         7a                                        Exception Id
                   d                                1a                                        Reserved
                   d  msgdata                     500a
              
                    * indicators for getHtmlIfsMult subprocedure
                   d IfsMultIndicators...
                   d                 ds
                   d  NoErrors                           like(boolean)
                   d  NameTooLong                        like(boolean)
                   d  NotAccessible                      like(boolean)
                   d  NoFilesUsable                      like(boolean)
                   d  DupSections                        like(boolean)
                   d  FileIsEmpty                        like(boolean)
              
                    *****************************************************************
                    * Stand Alone Fields Declaration
                    *****************************************************************
                    * like prototypes
                   d boolean         s               n
                   d int32           s             10i 0
              
                   d CGITESThtml     c                   '/rdwifs/html/'
                   d nbrVars         s                   like(int32)
              
                   d htmlMsgStr      s           1000a   varying
              
                   d savedQueryString...
                   d                 s          32767a   varying
              
                   d imgparm         s             32a   inz(*blanks)
              
                    * constants
                   d newline         c                   const(X'15')
                   d htmlHeader      c                   'Content-type: text/html'
                   d htmlErrMsg      c                    '<html><body> -
                   d                                      <p>An error occurred. -
                   d                                      Programmer has been notified. -
                   d                                      Please try again later. -
                   d                                      </p></body></html>'
              
                    *****************************************************************
                    * Mainline
                    *****************************************************************
                    /free
                       exsr initProgram;
              
                      // read externally defined output html files
                       IfsMultIndicators = getHtmlIfsMult('' +
                                             CGITESThtml + 'helloimg.html' + ''
                                             :'<!-- $':'$ -->');
              
                      // output HTML message if fail to load HTML templates and exit
                       if NoErrors = *off;
                         exsr failLoadHtml;
                         exsr exitProgram;
                       endif;
              
                       // get input
                       nbrVars = zhbGetInput(savedQueryString:qusec);
              
                       if nbrVars > 0;
                         imgparm = zhbGetVar('img');
                       endif;
              
                       if imgparm = *blanks;
                         updHtmlVar('imgfile':'no img parm');
                       else;
                         updHtmlVar('imgfile':imgparm);
                       endif;
              
                       // complete send of buffered output to the browser
                       wrtSection('showimg *fini');
              
                       exsr exitProgram;
              
                     //**************************************************************
                     //  Subroutine: failLoadHtml
                     //**************************************************************
                       begsr failLoadHtml;
              
                         htmlMsgStr = htmlHeader + newline + newline + htmlErrMsg;
                         wrtNoSection(%addr(htmlMsgStr)+2:
                                      %len(htmlMsgStr));
                         wrtSection('*fini');
              
                       endsr;
              
                     //**************************************************************
                     //  Subroutine: exitProgram
                     //**************************************************************
                       begsr exitProgram;
              
                         *inlr = *on;
                         return;
              
                       endsr;
              
                     //**************************************************************
                     //  Subroutine: initProgram
                     //**************************************************************
                       begsr initProgram;
              
                         // clear messages
                         clrMsgs();
              
                         // clear the HTML buffer
                         if getHtmlBytesBuffered > 0;
                           clrHtmlBuffer();
                         endif;
              
                       endsr;
                    /end-free
              [/FONT]
              HELLOIMG.HTML
              Code:
              [FONT=Courier New]<!-- $showimg$ -->
              Content-type: text/html
              
              <html>
              <body>
              <p>/%imgfile%/</p>
              <img src="http://IBMiURL//%imgfile%/"/>
              </body>
              </html>
              [/FONT]
              Last edited by tomholden; April 16, 2014, 09:33 AM. Reason: moved definitions from /copy to program D specs for standalone compile

              Comment


              • sheikhifti7
                sheikhifti7 commented
                Editing a comment
                it is giving me below error
                helloimg.pgm:4 GET http://10.200.65.227/cust_pics/4310187805577.jpg net::ERR_CONNECTION_REFUSED

              • JonBoy
                JonBoy commented
                Editing a comment
                I suggest you start a new thread. It is just plain confusing when a new question gets added to a 6 year old thread. We need to know what "it" is in this context. The file you reference doesn't appear to appear elsewhere in the thread.

              • ralphdaugherty
                ralphdaugherty commented
                Editing a comment
                sheikhifti7 - The nature of your problem is now in general realm. You could start a new thread saying I am trying to retrieve an image on my system with CGIDEV2 and getting this error, etc. The exact source code isn't an issue, just the general nature of accessing files via url and from the same system. You would get much better help that way. I would just say you should be able to paste that url into your browser and retrieve the image, and deal with any problems that way first. Whatever problems there are wouldn't be based on the particulars of this source code.

            • #8
              Re: CGIDEV2 to present JPGs stored on the IFS?

              a couple of corrections. My example URL at top should say helloimg followed by the img= parm, not showimg. helloimg is the name of the CGI program. showimg is the name of the CGIDEV2 template section.

              Also I can't see my post yet because its awaiting moderation, but the img src= line with parm in it could have got clobbered. Basically it's img src = IBM i URL plus the CGIDEV2 variable imgfile just above it which I display as name of file above the image.

              Hope that helps.

              Comment


              • #9
                Re: CGIDEV2 to present JPGs stored on the IFS?

                Hi Ralph, glad to see you here. I'm guessing there will be more and more refugees from the iProDeveloper forums finding their way here. Once you are in the "circle of trust", then you won't have to wait for moderation. Posting code works well (see the icons) and you'll be able to edit your posts.

                Anyway, thanks for posting your thoughts and test code. I will be getting CGIDEV2 configured and then I will run a test like what you have posted.

                One thing I think I will need to figure out how to get around is that we have QCCSID set to 65535 on this system, and I've been told that it has to stay that way due to other software that requires it... (Grrrr...) I don't suppose you've had to worry about that?

                Comment


                • #10
                  Re: CGIDEV2 to present JPGs stored on the IFS?

                  Viking

                  do you have the job's CCSid? That is actually what matters!

                  Comment


                  • #11
                    Re: CGIDEV2 to present JPGs stored on the IFS?

                    Henrik, I would have liked to set QCCSID to 37 as we are in the US. We don't run anything international. So instead I will need to specify CCSID = 37 for the jobs. Do I need to do anything special when configuring CGIDEV2? Is it just the CGIDEV2 server job that needs to have its job CCSID set to 37?

                    Comment


                    • #12
                      Re: CGIDEV2 to present JPGs stored on the IFS?

                      thanks for the welcome, Viking. I'm lucky Henrik mentioned these forums, I didn't know about them. Very nice.

                      I looked for a Code button and did a search for any posts about it, but I didn't see it. I will use it if I can find it.

                      I was going to suggest the job ccsid as well. As Henrik said, only thing that really matters, just doesn't have a default you want in your situation. I don't know where you set it for a CGI server job which I configure with HTTP Admin, I expect there is very complete support for it. Files and maybe other objects like that are the other main thing with ccsid. I remember back in '96 I had a problem with files having a 65535 ccsid and they needed to stay up for months and couldn't be changed to 37. IBM was working on a live PF change at the time to do that, which they did, but didn't help me at the time. I don't remember what the problem was, but I think I did a programmatic EBCDIC - ASCII translation. These days it would be UTF-8? I would need to revisit Scott's tutorial on that.

                      Comment


                      • #13
                        Re: CGIDEV2 to present JPGs stored on the IFS?

                        Ralph- welcome

                        you have to go "advanced" in your postings - there is a bottom that inserts {code} hey here i can post code {/code} just in brackets

                        Comment


                        • #14
                          Re: CGIDEV2 to present JPGs stored on the IFS?

                          I updated the post with Code tags but either I clobbered it pretty good or it's awaiting moderation.

                          Comment


                          • #15
                            Re: CGIDEV2 to present JPGs stored on the IFS?

                            Viking

                            if you do a DSPJOB option 2 page 3 what is the job's CCSID?

                            Comment

                            Working...
                            X