Thursday, April 4, 2019

PS 12+ Contact Export with Employer

<!DOCTYPE html>
<html>
<!-- start right frame -->
<head>
    <title>Contacts Employer Export</title>
    <link href="/images/css/screen.css" rel="stylesheet" media="screen">
    <link href="/images/css/print.css" rel="stylesheet" media="print">


</head>
<body>
    ~[wc:admin_header_frame_css]
   
    <!-- breadcrumb start -->
    <a href="/admin/home.html" target="_top">~[text:psx.html.admin_students.unlimitedcontacts.start_page]</a> &gt;
    <a href="home.html?selectstudent=nosearch" target="_top">~[text:psx.html.admin_students.unlimitedcontacts.student_selection]</a> &gt;
    Contacts Export
    <!-- breadcrumb end -->
   
    ~[wc:admin_navigation_frame_css]

<!-- start of title and student content -->


<table width="100%">
<tr>
<td background="/images/transparent.gif">

<!-- title -->
<h1>Contacts Employer Export</h1>
<!-- title -->


<input type="button" value="Export as Excel" onclick="saveAsExcel('contactExport', 'contactExport.xls')"/>

~[if.isstudent]
<!-- don't allow students to view the directory. -->

<!-- start of content and bounding box -->
<table>
<tr>
<td width="23" background="/images/bond_box_left_edge.gif"><img src="/images/spacer.gif" width="23" height="1"></td>
<td>
<table>
<tr>
<td>Your account does not allow access to this page.</td>
</tr>
</table>
</td>
<td width="25" background="/images/bond_box_right_edge.gif"><img src="/images/spacer.gif" width="25" height="1"></td>
</tr>
</table>
<br>
<!-- end of content of bounding box -->

[else]

<table id="contactExport" class="grid" style="width:100%">
<tr>
  <th>Student Full Name</th>
  <th colspan=10>Contact Information</th>
</tr>

~[tlist_sql;
WITH StudentsParents AS (
    SELECT DISTINCT
        DECODE(co.ContactRelationship,'Mother','M','Father','F','Step-Mother','M','Step-Father','F','X') ContactRelationship,
        co.StudentDCID,
        co.ContactLastFirst,
        pp.PhoneNumberasentered,
        e.EmailAddress,
        co.Employer
    FROM
        PSSIS_STU_Contact_Act co
        LEFT JOIN PSSIS_Person_Phone pp on pp.PersonID = co.ContactPersonDCID AND pp.isPreferred = 1
        LEFT JOIN PSSIS_Person_Email e  on e.PersonID  = co.ContactPersonDCID AND e.isPrimaryEmailAddress = 1
    WHERE co.Employer is not null
)
SELECT DISTINCT
    s.lastfirst,
    DECODE(m.ContactLastFirst ,'','',
        '<td class="right bold">Mother</td><td>' || m.ContactLastFirst || '</td>' ||
        /* CHR(58) is a colon. Actual colons break TLIST_SQL. */
        '<td>' || m.PhoneNumberasentered || '</td>' ||
        '<td>' || m.EmailAddress || '</td>' ||
        '<td>' || m.Employer || '</td>') AS Mother,
    DECODE(f.ContactLastFirst ,'','',
        '<td class="right bold">Father</td><td>' || f.ContactLastFirst || '</td>' ||
        /* CHR(58) is a colon. Actual colons break TLIST_SQL. */
        '<td>' || f.PhoneNumberasentered || '</td>' ||
        '<td>' || f.EmailAddress || '</td>' ||
        '<td>' || f.Employer || '</td>') AS Father
FROM
    Students s
    LEFT JOIN StudentsParents m ON s.DCID = m.StudentDCID AND m.ContactRelationship = 'M'
    LEFT JOIN StudentsParents f ON s.DCID = f.StudentDCID AND f.ContactRelationship = 'F'
WHERE
    s.enroll_status in (0,-1)
ORDER BY
    LOWER(s.lastfirst) ; ]
    <tr valign="top">
    <td>~(s.lastfirst)</td>
    ~(MotherRow)
    ~(FatherRow)
    </tr>

[/tlist_sql]

</table>
<!-- end student content -->

[/if.isstudent]

</td>
</tr>
</table>
<!-- end of title and student content -->

<p>NOTE:  In order for the contact's information to show up, either the preferred phone number and primary email must be checked off.</p>


<!-- JN Export using TableExport.js -->
<!-- <script type="text/javascript" src="/admin/javascript/xlsx.core.js"></script>
<script type="text/javascript" src="/admin/javascript/Blob.min.js"></script>
<script type="text/javascript" src="/admin/javascript/FileSaver.min.js"></script>
<script type="text/javascript" src="/admin/javascript/TableExport.min.js"></script>
<script>
    var FormatsTable = document.getElementById('contactExport');
    new TableExport(FormatsTable, {
        formats: ['xlsx', 'csv']
    });
</script> -->

<script type="text/javascript" src="/admin/javascript/saveAsExcel.js"></script>

</body>
</html>